【问题标题】:Laravel Migrations breaks when migrating new tables into the database将新表迁移到数据库时 Laravel 迁移中断
【发布时间】: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


    【解决方案1】:

    是不是说 CreateUsersTable 类已经存在?

    我可以看到类名是 CreateUsersTable,但你应该重命名为 CreateDriversTable

    【讨论】:

    • 不错@Brett。
    猜你喜欢
    • 2019-01-26
    • 2017-03-30
    • 2019-10-10
    • 2016-07-23
    • 2021-06-04
    • 2017-02-21
    • 2018-04-04
    • 2021-11-07
    • 2017-12-11
    相关资源
    最近更新 更多