Объясните, как исправить данную ошибку с FK.
Код:
cur.execute('''CREATE TABLE Vm
(id_vm INT PRIMARY KEY NOT NULL,
uuid_vm CHAR(100) NOT NULL,
name_vm CHAR(100) NOT NULL,
bg_date DATE NOT NULL,
end_date DATE DEFAULT('2999-05-12'))
''')
cur.execute('''CREATE TABLE Vm_parm
(id_parm INT PRIMARY KEY NOT NULL,
title CHAR(30) NOT NULL,
type CHAR(10) NOT NULL)
''')
cur.execute('''CREATE TABLE Vm_stat
(id_stat INT PRIMARY KEY NOT NULL,
uuid_vm CHAR(100) NOT NULL,
name_vm CHAR(100) NOT NULL,
bg_date DATE NOT NULL,
end_date DATE NOT NULL,
vm_parm CHAR(30) NOT NULL,
value_parm INT NOT NULL)
''')
cur.execute("ALTER TABLE Vm_stat ADD CONSTRAINT fk_Vm_stat_uuid_vm_name_vm_bg_date_end_date FOREIGN KEY(uuid_vm, name_vm, bg_date, end_date)"
"REFERENCES Vm (uuid_vm, name_vm, bg_date, end_date)")
cur.execute("ALTER TABLE Vm_stat ADD CONSTRAINT fk_Vm_stat_vm_parm FOREIGN KEY(title)"
"REFERENCES Vm_parm(title)")
Выдаёт мне вот такую ошибку:
line 34, in <module>
cur.execute("ALTER TABLE Vm_stat ADD CONSTRAINT fk_Vm_stat_uuid_vm_name_vm_bg_date_end_date FOREIGN KEY (uuid_vm, name_vm, bg_date, end_date)"
psycopg2.errors.InvalidForeignKey: there is no unique constraint matching given keys for referenced table "vm"