@KuzmenkoArtem

Миграции в Laravel. Не получается создать связи?

Schema::create('companies_owners_connections', function (Blueprint $table) {
            $table->integer('company_id')->unsigned();
            $table->integer('id_owner')->unsigned();
        });
        
        Schema::table('companies_owners_connections', function(Blueprint $table){
            $table->index('company_id');
            $table->index('id_owner');
            
            $table->foreign('company_id')->references('id')->on('company')->on_delete('restrict');
            $table->foreign('company_id')->references('id')->on('company')->on_update('cascade');
            $table->foreign('id_owner')->references('id')->on('owners')->on_delete('restrict');
            $table->foreign('id_owner')->references('id')->on('owners')->on_update('cascade');
        });


Через phpMyAdmin все работает.

Artisan:
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL
: alter table `companies_owners_connections` add constraint companies_owner
s_connections_company_id_foreign foreign key (`company_id`) references `com
pany` (`id`))

В чем может быть проблема?
  • Вопрос задан
  • 281 просмотр
Решения вопроса 1
ZLOFENIX
@ZLOFENIX
Абсолютно поехавший
Гугл говорит, что почти всегда это из-за несовпадения типов полей.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

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

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