0

I'm working with python2 and sqlite3 (3.11 exactly) and I have created two tables, one of which has a Foreign Key, this is the code of my tables:

CREATE TABLE IF NOT EXISTS users(
                            id INT PRIMARY KEY AUTOINCREMENT,
                            name TEXT NOT NULL,
                        );
CREATE TABLE IF NOT EXISTS locations(
                            id INTEGER PRIMARY KEY AUTOINCREMENT,
                            user INT NOT NULL,
                            latitude REAL NOT NULL,
                            longitude REAL NOT NULL,
                            FOREIGN KEY (user) REFERENCES users(id)
                        );

The tables are created, and the problem comes when I insert locations of users that doesn't exists on users table. It doesn't give me any error, so it looks like the foreign key is not working. I have tried executing PRAGMA foreign_keys = 1 each time I connect to the database, but still nothing.

Any ideas?

Thanks

Javierd98
  • 708
  • 9
  • 27

0 Answers0