douao1858 2013-12-26 19:01
浏览 10
已采纳

使用油CLI在FuelPHP中更改表结构

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');
    }
}
  • 写回答

1条回答 默认 最新

  • dsfsdf7852 2013-12-27 15:58
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM