2

im making an app with some SQLite database but It crashes by an SQLite Syntax error (Android Studio Debug Report)

CREATE TABLE paneles(id INTEGER PRIMARY KEY, mega_id INTEGER, FOREIGN KEY (mega_id) REFERENCES megas(id), codigobarras INTEGER,nombre TEXT); 

it says is near codigobarras, but I can't find the error

thanks for help

1 Answer 1

2

Move the FOREIGN KEY (mega_id) REFERENCES megas(id) at the end of your CREATE TABLE.

In the SQL syntax, column specifications come first and table constraints such as FOREIGN KEY after that. No column specifications can follow the table constraints, hence the syntax error.

Reference: https://www.sqlite.org/lang_createtable.html

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.