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));

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

1 Answer 1


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.

  • 2
    You can also use the compact syntax: webserver_id integer REFERENCES target_dp(id) Apr 23, 2015 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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