【发布时间】:2022-01-23 09:10:29
【问题描述】:
我正在尝试将 Laravel 表迁移迁移到数据库中,但是每次我创建新表并运行 php artisan migrate Laravel 都会抱怨用户表存在,甚至新添加的迁移都没有在数据库中创建,当我运行 @987654322 时@我丢失了我的数据有没有更好的方法来做到这一点而不会丢失我已经存在的表中的数据。下面是我要添加的表格。
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up() {
Schema::create('drivers', function (Blueprint $table) {
$table->id();
$table->string('name')->nullable();
$table->string('email')->unique();
$table->string('contact')->unique()->nullable();
$table->string('code')->unique();
$table->string('nin')->nullable();
$table->date('birthday')->nullable();
$table->string('image')->nullable();
$table->bigInteger('country_id')->nullable();
$table->boolean('verified')->nullable()->default(false);
$table->timestamps();
$table->foreign('country_id')->references('id')->on('countries');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down() {
Schema::dropIfExists('drivers');
}
}
【问题讨论】:
标签: php laravel eloquent database-migration