@smilelan

Как правильно связать базы?

Пытаюсь связать 2 таблицы, при миграции вылазит ошибка SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "roles" does not exist (SQL: alter table "users" add constraint "users_role_id_foreign" foreign key ("role_id") references "roles" ("id_role"))
. Не пойму в чем дело
class CreateUsersTable extends Migration
{
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('role_id')->unsigned();
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();

            $table->foreign('role_id')->references('id_role')->on('roles');
        });
    }
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

class CreateRolesTable extends Migration
{
    public function up()
    {
        Schema::create('roles', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('id_role');
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::dropIfExists('roles');
    }
}
  • Вопрос задан
  • 249 просмотров
Пригласить эксперта
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы
18 апр. 2024, в 11:47
30000 руб./за проект
18 апр. 2024, в 11:46
5000 руб./за проект
18 апр. 2024, в 11:43
10000 руб./за проект