A
A
Amir Shabanov2016-01-18 09:21:40
Python
Amir Shabanov, 2016-01-18 09:21:40

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

1 answer(s)
A
angru, 2016-01-18
@angru

isn't it:
a ="""... user_id INTEGER,
FOREIGN KEY....
"""
?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question