think-migration 创建表失败

问题描述

按照这个入门实战敲的代码 https://www.kancloud.cn/inbuf...
做到第6章验证那里的时候发现不管是否验证正确,都是报错数据库表不存在。当时还不确认一定是数据库表没建立成功,怕也有其他原因导致,然后我就从验证那个章节往前面查找原因,最后发现就是在第5章第2节那里数据迁移发生了问题。应该是在这里创建表的时候就失败了。

 // create the table
        $table = $this->table('users');
        $table->addColumn('name', 'string')
            ->addColumn('email', 'string')
            ->addColumn('password', 'string')
            ->addColumn('avatar', 'string', ['null' => true, 'default'=>NULL, 'comment'=>'用户头像'])
            ->addColumn('god', 'boolean', ['default'=>FALSE, 'comment'=>'管理员'])
            ->addTimestamps('created_at', 'updated_at')
            ->addIndex('email', ['unique' => true])
            ->addIndex('god')
            ->create();

我的代码也是有这些,所以不知道为什么表没有创建成功。

阅读 2.1k
1 个回答

自己找到了答案了,
http://docs.phinx.org/en/late...
文档介绍到

Please be aware that when a change method exists, Phinx will automatically ignore the up and down methods.

也就是说 当change方法存在的时候,Phinx会自动忽略up和down方法。

而我这之前无法创建users表就是因为,在它自动创建的migration文件里面添加了up和down方法,但是自动添加的change方法虽然是空的,但是我即没有删除也没有注释掉。而放在了up和down方法的前面。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题