【发布时间】:2016-07-11 12:10:03
【问题描述】:
为什么不能,而且似乎没什么可迁移的?
迁移的时候创建表authors和books都可以,但是外键之后就不行了
迁移添加外来:
public function up()
{
Schema::table('books', function(Blueprint $table) {
$table->foreign('author_id')->references('id')->on('authors')
->onDelete('restrict')
->onUpdate('cascade');
});
}
使用这个:
php artisan migrate
还有这个:
php artisan migrate --path=app/database/migrations/2016_07_11_105204_add_foreign_key_to_books.php
还是不行,
桌书:
public function up()
{
Schema::create('books', function(Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->integer('author_id')->unsigned();
$table->integer('amount')->unsigned();
$table->timestamps();
});
}
表作者:
public function up()
{
Schema::create('authors', function(Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});
}
感谢您的帮助..
【问题讨论】:
-
如果您手动添加了迁移,请尝试
composer dumpautoload以使其被识别。