@aleshaykovlev
html, css, js, node, webpack, sass, react

Почему ошибка при обновлении миграции?

Миграция паспорта:
return new class extends Migration
{
    public function up()
    {
        Schema::create('passports', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id');
            $table->foreign("user_id")->references("id")->on("users");
            $table->string("series");
            $table->string("num");
            $table->timestamps();
        });
    }
};

Миграция пользователя:
return new class extends Migration
{
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('first_name');
            $table->string('last_name');
            $table->string('patronymic');
            $table->string('email')->unique();
            $table->string('password');
            $table->text('description')->default("Нет описания");
            $table->string('city')->nullable()->default("Нет города");
            $table->string('age')->default("Нет возраста");
            $table->string('avatar')->default("https://static-00.iconduck.com/assets.00/avatar-default-symbolic-icon-512x488-rddkk3u9.png");
            $table->rememberToken();
            $table->timestamps();
        });
    }
};

Пишу php artisan migrate, они создаются, потом обновляю миграцию пользователя:
$table->unsignedBigInteger('passport_id');
$table->foreign("passport_id")->references("id")->on("passports");

Пишу php artisan migrate:fresh и выдает ошибку:
Illuminate\Database\QueryException 

  SQLSTATE[42P01]: Undefined table: 7 ОШИБКА:  отношение "passports" не существует (SQL: alter table "users" add constraint "users_passport_id_foreign" foreign key ("passport_id") references "passports" ("id"))

(при первом создании в бд все таблицы хранятся)
  • Вопрос задан
  • 85 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы