8
respostas

Migration não cria tabela.

Fiz o exercício, mas ao executar, aparece a mensagem "migrado", porém no banco não cria a tabela, ao invés disso aparece uma tabela em branco chamada migration.

8 respostas

Oi Ruben, tudo bom?

Posso dar uma olhada no seu aquivo 001_cria_tabela_de_vendas.php ?

Aguardo retorno.

Abraço!

Segue código

<?php

class Migration_Cria_tabela_de_vendas extends CI_migration {

public function up() {
    $this->dbforge->add_field(array(
        'id' => array(
            'type' => 'INT',
            'auto_increment' => true
        ),
        'produto_id' => array (
            'type' => 'INT'
        ),
        'comprador_id' => array(
            'type' => 'INT'
        ),
        'data_de_entrega' => array(
            'type' => 'DATE'
        )
    ));
    $this->dbforge->add_key('id', true);
    $this->dbforge->create_table('vendas');
}



    public function down() {
        $this->dbforge->drop_table('vendas');
    }    

}    

?>

Oi Ruben, não me parece ter nada de errado na sua migration mesmo...

Posso dar uma olhada no seu arquivo migration.php? e no controller Utils também se possivel?

Assim a gente consegue dar uma olhada em todos os possiveis pontos desse problema =)

Aguardo retorno!

Claro:

<?php defined('BASEPATH') OR exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| Enable/Disable Migrations
|--------------------------------------------------------------------------
|
| Migrations are disabled by default but should be enabled 
| whenever you intend to do a schema migration.
|
*/
$config['migration_enabled'] = TRUE;


/*
|--------------------------------------------------------------------------
| Migrations version
|--------------------------------------------------------------------------
|
| This is used to set migration version that the file system should be on.
| If you run $this->migration->latest() this is the version that schema will
| be upgraded / downgraded to.
|
*/
$config['migration_version'] = 1;


/*
|--------------------------------------------------------------------------
| Migrations Path
|--------------------------------------------------------------------------
|
| Path to your migrations folder.
| Typically, it will be within your application path.
| Also, writing permission is required within the migrations path.
|
*/
$config['migration_path'] = APPPATH . 'migrations/';

$config['migration_type'] = 'sequential';


/* End of file migration.php */
/* Location: ./application/config/migration.php */

Agora o controller:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Utils extends CI_Controller {

    public function migrate() {

        $this->load->library("migration");
        $success = $this->migration->current();
        if($success) {
            echo 'migrado';
        } else {
            show_error($this->migration->error_string());
        }

    }
}

Oi Ruben, realmente não parece ter nenhum problema com a configuração do seu ambiente.

Qual o conteudo da tabela "migration" que foi gerada? mostra as colunas dela aqui pra gente? Talvez fique mais claro a origem do problema =)

Abraço!

Apenas uma coluna "version" e o valor que aparece nela é 0.

Olá! mesmo problema! acho que é algo do codeigniter 3!

Alguma solução por ai?

Estou tendo o mesmo problema aqui também .

Alguém encontrou o porque?

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software