serial not null constraint account_pkey primary key,
                  
                  
                      email text not null,
                  
                  
                      password text not null,
                  
                  
                  );
                  
                  
                  
                  
                  
                  create table user_role (
                  
                  
                      user_id integer not null constraint account_role_account_id_fkey references "user",
                  
                  
                      role_id integer not null,
                  
                  
                      created_at timestamp(0) default timezone('UTC'::text, now()) not null,
                  
                  
                      constraint account_role_pkey primary key (user_id, role_id)
                  
                  
                  );
                  
                  
                  
                  
                  
                  Хочу удалить юзера. Делаю так:
                  
                  
                  
                  
                  
                  DELETE FROM "user" CASCADE;
                  
                  
                  
                  
                  
                  Получаю
                  
                  
                  
                  
                  
                  update or delete on table "user" violates foreign key constraint "account_role_account_id_fkey" on table "user_role"
                  
                  
                  
                  
                  
                  В чём причина?
                  
                  
                
TRUNCATE some_table CASCADE
Надеюсь, он это в проде не попробует
Это для тестов. Но, опять же, может быть нужно очистить всю таблицу. Или есть сайд-эффекты.
> DELETE FROM "user" CASCADE; а как это работает? Postgres не умеет в CASCADE для DELETE же.
Как "DELETE FROM "user" AS CASCADE;" конечно. Таковы радости выдумывания несуществующего синтаксиса. :)
Обсуждают сегодня