2

I'm trying to run this code in sqlite:

sqlite> CREATE TABLE test(id integer primary key AUTOINCREMENT, page varchar(10), dp_record_id integer, foreign key (webserver_id) REFERENCES target_dp(id));

But I'm getting the following error message:

Error: unknown column "webserver_id" in foreign key definition

Here's the parent table:

sqlite> .schema
CREATE TABLE target_dp(id integer primary key AUTOINCREMENT, server_name varchar(255), location_code varchar(10), active bit(1));
sqlite> 

I can't see where my syntax error is. Thanks in advance for your time.

3

You are missing a webserver_id column in the TEST table.

CREATE TABLE test(id integer primary key AUTOINCREMENT
                , page varchar(10)
                , dp_record_id integer
                , webserver_id integer
                , foreign key (webserver_id) REFERENCES target_dp(id));

Works just fine.

1
  • 1
    You can also use the compact syntax: webserver_id integer REFERENCES target_dp(id) – ypercubeᵀᴹ Apr 23 '15 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.