問題描述
我正在嘗試使用 Laravel Migration 創建 SQL 表,但它不讓我使用.
I am trying to use Laravel Migration to create SQL tables but it won't let me.
這里是錯誤:
SQLSTATE[42S01]:基表或視圖已經存在:1050 表'mytable' 已經存在
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'mytable' already exists
這是我的代碼:
Schema::create('mytable', function (Blueprint $table) {
$table->increments('id');
$table->foreign('othertable_id')
->references('id')->on('othertable')
->onDelete('cascade');
$table->string('variable');
$table->timestamps();
});
}
{
Schema::drop('mytable');
}
我還檢查了其他遷移是否稱為mytable",但它們不是,所以我不確定這是從哪里來的.
I have also checked if other migrations are called "mytable" but they are not, so I am not sure where this come from.
我嘗試了以下方法:
第一次
php artisan migrate:refresh
這給了我一個錯誤
然后我刪除了整個數據庫并使用:
And then I deleted the entire database altogheter and used:
php artisan migrate
還是報錯
推薦答案
do composer dump
,手動從數據庫中刪除表,并刪除要從中刪除的表的遷移條目遷移表并再次重新運行遷移以查看會發生什么.
do composer dump
, remove the table manually from the database and also remove the migration entry for the the table you want to remove from the migration table and rerun the migration again to see what happens.
這篇關于Laravel 不允許我遷移表,因為它已經存在的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!