Answer the question
In order to leave comments, you need to log in
How to create Foreign Key in SQLite via Framework bottle.py?
I am creating a relational database where there is a Users table and a Todotable table, and I get an error when key bindings (foreign key), here is the actual code:
class TODOTABLE:
@classmethod
def init(self):
conn = sqlite3.connect('test.db ')
cursor = conn.cursor()
a = "select name from sqlite_master where type='table' and name='TODOTABLE'"
result = cursor.execute(a).fetchone()
if not result:
a = """
create table TODOTABLE(
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
text char(100),
author char(20),
datechar,
user_id INTEGER foreign key(user_id) references User(id)
)"""
cursor.execute(a)
conn.commit()
print("table for TODOTABLE created")
and here is the actual error:
cursor.execute(a)
sqlite3. OperationalError: near "foreign": syntax error
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question