Question

I created a table using oil generate CLI command and the table was created as required.

php oil generate scaffold <details>

Now I wanted to change few columns and add a new column to the table strcutre. I used the oil refine and it ran.

php oil refine migrate -all

But there is no changes done to the table. Migration details are provided below (chnage of a column - 'created').

Old migration file: 003_create_categories.php

<?php

namespace Fuel\Migrations;

class Create_categories
{
    public function up()
    {
    \DBUtil::create_table('categories', array(
        'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true, 'unsigned' => true),
        'name' => array('constraint' => 255, 'type' => 'varchar'),
        'description' => array('type' => 'text'),
        'image' => array('constraint' => 255, 'type' => 'varchar'),
        'created' => array('type' => 'datetime'),
        'created_at' => array('constraint' => 11, 'type' => 'int', 'null' => true),
        'updated_at' => array('constraint' => 11, 'type' => 'int', 'null' => true),

    ), array('id'));
    }

    public function down() {
    \DBUtil::drop_table('categories');
    }
}

New migration file: 004_create_categories.php

<?php

namespace Fuel\Migrations;

class Create_categories
{
    public function up()
    {
    \DBUtil::create_table('categories', array(
        'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true, 'unsigned' => true),
        'name' => array('constraint' => 255, 'type' => 'varchar'),
        'description' => array('type' => 'text'),
        'image' => array('constraint' => 255, 'type' => 'varchar'),
        'status' => array('type' => 'tinyint'),
        'created_at' => array('constraint' => 11, 'type' => 'int', 'null' => true),
        'updated_at' => array('constraint' => 11, 'type' => 'int', 'null' => true),

    ), array('id'));
    }

    public function down() {
    \DBUtil::drop_table('categories');
    }
}
Was it helpful?

Solution

Migration files are designed to build on each other. You don't need to create the table in every migration. Fuel will run your 003 migration, and then your 004 migration which will fail because the table already exists.

Your 004 migration should only contain a description of how to update the table from its previous state. Ie, add your new column.

The "down" of your migration should do the opposite as well. So your 004 migration's down should remove the column.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top