Hi,
Ich verwende Django mit Postgresql und irgendwie funktioniert ein Unique-constrain nicht… Das Merkwürdige an der Sache ist bloß das die generierte Tabelle auf mich richtig wirkt. Wenn ich mich nicht irre sollte ja diese Tabelle nicht möglich sein:
Id | permission_type | source_group_id | source_profile_id | target_group_id | target_profile_id |
---|---|---|---|---|---|
1 | 2 | 2 | null | null | 14 |
2 | 2 | 2 | null | null | 14 |
Order habe ich ein knick in der Logik? Hier die Tabelle:
-- auto-generated definition
create table permission
(
id serial not null
constraint permission_pkey
primary key,
permission_type smallint not null,
source_group_id integer
constraint permission_source_group_id_ad885e0f_fk_usc
references group
deferrable initially deferred,
source_profile_id integer
constraint permission_source_profile_id_101e9831_fk_usc
references profile
deferrable initially deferred,
target_group_id integer
constraint permission_target_group_id_22a58b31_fk_usc
references group
deferrable initially deferred,
target_profile_id integer
constraint permission_target_profile_id_f3fc37f3_fk_usc
references profile
deferrable initially deferred,
constraint "constrainError.permissionExists"
unique (source_profile_id, source_group_id, target_profile_id, target_group_id),
constraint "constrainError.onlyOneSource"
check (((source_group_id IS NOT NULL) AND (source_profile_id IS NULL)) OR
((source_group_id IS NULL) AND (source_profile_id IS NOT NULL))),
constraint "constrainError.onlyOneTarget"
check (((target_group_id IS NOT NULL) AND (target_profile_id IS NULL)) OR
((target_group_id IS NULL) AND (target_profile_id IS NOT NULL))),
constraint "constrainError.groupsCantBeSupervisor"
check ((source_group_id IS NULL) OR ((permission_type > 1) AND (source_group_id IS NOT NULL)))
);
alter table permission
owner to alamanda;
create unique index "constrainError.onlyOneSupervisorPerGroup"
on permission (target_group_id)
where (permission_type = 1);
create unique index "constrainError.onlyOneSupervisorPerProfile"
on permission (target_profile_id)
where (permission_type = 1);
create index permission_source_group_id_ad885e0f
on permission (source_group_id);
create index permission_source_profile_id_101e9831
on permission (source_profile_id);
create index permission_target_group_id_22a58b31
on permission (target_group_id);
create index permission_target_profile_id_f3fc37f3
on permission (target_profile_id);
Grüße, Alamanda