S
S
stepan-neretin72019-04-21 22:14:16
Laravel
stepan-neretin7, 2019-04-21 22:14:16

How to add nullable to given field?

First there is such a migration => Tyk
I need to add null to cards.city_id (so that they can be)
Created such a migration

Schema::table('cards', function (Blueprint $table) {
            $table->integer('city_id')->nullable()->change();
        });

Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1832 Cannot change column 'city_id': used in a foreign key constraint 'cards_city_id_foreign' (SQL: ALTER TABLE cards CHANGE city_id city_id INT DEFAULT
NULL
) ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Arutyunov, 2019-04-21
@arutyunov

Remove the foreign key, then make the field nullable. After that, create the foreign key again.

G
Gregory K., 2019-04-21
@ShGKme

1. 2. Then make the field nullable. 3. Then againDB::statement('SET FOREIGN_KEY_CHECKS = 0;');
DB::statement('SET FOREIGN_KEY_CHECKS = 1;');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question