K
K
kamwork2017-04-18 21:18:31
PostgreSQL
kamwork, 2017-04-18 21:18:31

How to overcome the transition to Postgres and the problem with FOREIGN KEY?

Hello.
I am using the Laratrust component for roles in a project.
It has a table:

// Create table for associating roles to users (Many-to-Many)
        Schema::create('role_user', function (Blueprint $table) {
            $table->integer('user_id')->unsigned();
            $table->integer('role_id')->unsigned();

            $table->foreign('user_id')->references('id')->on('users')
                ->onUpdate('cascade')->onDelete('cascade');
            $table->foreign('role_id')->references('id')->on('roles')
                ->onUpdate('cascade')->onDelete('cascade');

            $table->primary(['user_id', 'role_id']);
        });

When I try to make Seed, I get an error:
6b464acc474c4126801e8427e030f16c.jpg8fc0d624a58f4a20b589a597e47a14db.jpg
Tell me where to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
egor_nullptr, 2017-04-19
@kamwork

SET FOREIGN_KEY_CHECKSworks only in MySQL, in Postgres there is no such thing, you need to disable one table at a time. - disable - enable
ALTER TABLE permission_role ENABLE TRIGGER ALL

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question