Important: Please read the Qt Code of Conduct -

Relation btween tables

  • hello this my code

    @if((query.exec("CREATE TABLE artist ( id INTEGER PRIMARY KEY,name VARCHAR(40) NOT NULL,country VARCHAR(40))"))&&(query.exec("CREATE TABLE cd ( id INTEGER PRIMARY KEY,title VARCHAR(40) NOT NULL,artistid INTEGER NOT NULL,year INTEGER NOT NULL,FOREIGN KEY (artistid) REFERENCES artist)")))@
    am trying to create to tables and relation btween but i have this error

    Can't create table '' (errno: 150) QMYSQL: Unable to execute query
    please help me

  • Moderators

    My SQL is a little rusty but shouldn't it be something like this?
    @...FOREIGN KEY (artistid) REFERENCES artist(id)@
    with the (id) at the end.

  • thank you chris kawa it's work

Log in to reply