class CreateCommentsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email');
$table->text('comment');
$table->boolean('approved');
$table->integer('post_id')->unsigned();
$table->timestamps();
});
Schema::table('comments', function (Blueprint $table) {
$table->foreign('post_id')->references('id')->on('posts');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropForeign(['post_id']);
Schema::dropIfExists('comments');
}
}
这是我的移民类是什么样子,我一直在试图从数据库中删除表,但它引发我一个错误。调用未定义的方法照亮数据库架构 MySqlBuilder :: dropForeign()
错误
调用未定义的方法照亮\数据库\架构\ MySqlBuilder :: dropForeign()
我已经通过文件走了,但它亘古不变的似乎是有很大帮助。
任何人都可以请指出我的错误,什么是解决方案?
就这么你知道,我是新来的laravel.Go容易对我。谢谢!
如果仅指定键,它应该是一个数组。否则它不会工作。 –
是的,迁移中外键的命名约定是' _ _ _foreign',对吧? –
shoieb0101
是的。在Laravel 5中你也可以使用key,但它应该在数组里面,比如'dropForeign(['your_key_name'])' –