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');
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我的迁移类的样子,我一直在尝试从数据库中删除该表,但它引发了一个错误。
错误
调用未定义的方法 Illuminate\Database\Schema\MySqlBuilder::dropForeign()
我已经阅读了文档,但似乎没有太大帮助。
谁能指出我的错误以及解决方案是什么?
想让你知道,我是 Laravel 的新手。请对我宽容一点。谢谢!
dropForeignSchema::table需要用一个对象来调用Blueprint,
Schema::table('comments', function (Blueprint $table) {
$table->dropForeign('comments_post_id_foreign');
});
Run Code Online (Sandbox Code Playgroud)
这遵循 的命名约定<table_name>_<foreign_table_name>_<column_name>_foreign。
或者
Schema::table('comments', function (Blueprint $table) {
$table->dropForeign(['your_key_name']);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5017 次 |
| 最近记录: |