【问题标题】:Cakephp 3.0 bake error with foreign keys generated by Migrations迁移生成的外键 Cakephp 3.0 烘焙错误
【发布时间】:2016-09-27 23:08:16
【问题描述】:

我尝试在 cakephp 3 中烘焙我的 MVC。我使用 Migrations 创建了包含外键的表。这是我用于迁移的代码

{
$utTable = $this->table('unit_types');
    $utTable
        ->addColumn('unit_type_desc','string')
        ->addColumn('created','datetime')
        ->addColumn('modified','datetime')
        ->create();
    $mlTable = $this->table('master_lists');
    $mlTable
        ->addColumn('unit_type_id','integer')
        ->addForeignKey('unit_type_id', 'unit_types', 'id')
        ->addColumn('created','datetime')
        ->addColumn('modified','datetime')
        ->create();
}

它没有提示错误,似乎运行良好。但是当我烘焙主列表时,我遇到了一些错误,我看到了“0 列”短语或类似的内容。

现在我的问题是,这是在 cakephp 中放置数据关联的正确方法吗?还是我应该使用我的模型文件?我不知道。我是这个框架的新手。感谢您的任何回答。

【问题讨论】:

    标签: cakephp foreign-keys migration


    【解决方案1】:

    我不知道你是否解决了你的问题,但我建议你使用 save() 而不是 create()

    对于任何搜索相同主题的人,Cakephp 3 使用库 Phinx 来处理迁移,这里是有关您的问题的信息:http://docs.phinx.org/en/latest/migrations.html#working-with-foreign-keys

    【讨论】:

      猜你喜欢
      • 2014-04-21
      • 2013-02-06
      • 2015-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多