Error code 1005, SQL state HY000: Can't create table errno: 150

前端 未结 5 687
生来不讨喜
生来不讨喜 2021-01-01 06:40

I\'m trying to create a table but the script fails as soon as my netbeans errors the first table of DB.

How can this be solved?

CREATE TABLE filmy
(         


        
5条回答
  •  自闭症患者
    2021-01-01 07:13

    Here is my solution:

    CREATE TABLE filmy 
    ( 
        Film_Id           int           NOT NULL, 
        Nazwa             varchar(250)      NULL, 
        Adres             varchar(250)      NULL, 
        Data_Utworzenia   date              DEFAULT '0000-00-00', 
        Komentarz         varchar(250)      NULL, 
        Gat_Id            int               NULL, 
        Sub_Id            int               NULL, 
        Aut_Id            int               NULL, 
        User_Id           int               NULL, 
     Primary Key (Film_Id, Gat_Id, Sub_Id, Aut_Id, User_Id )
    ) ENGINE=INNODB;
    

    Foreign key constraints are done after creating the gat, sub, aut & user or else the ide does not know have the two tables existing to make the table constraint a reality! Try: alter table filmy add constraint gatfilmy foreign key (gat_id) references gat(gat_id) on update restrict on delete restrict you have to keep consistent; either name the table gat or gatunek, it cannot be both. How will the cpu know which is gat or gatunek if you do not define them both? Now try with the rest constraints and remember you ahve to create all the tables before you can alter them!

    CONSTRAINT fk_GatFilmy FOREIGN KEY (Gat_Id) REFERENCES gatunek(Gat_Id), 
    CONSTRAINT fk_SubFilmy FOREIGN KEY (Sub_Id) REFERENCES subgatunek(Sub_Id), 
    CONSTRAINT fk_AutFilmy FOREIGN KEY (Aut_Id) REFERENCES autor(Aut_Id), 
    CONSTRAINT fk_UserFilmy FOREIGN KEY (User_Id) REFERENCES users(User_Id) 
    

提交回复
热议问题