TryGhost / node-sqlite3

SQLite3 bindings for Node.js
BSD 3-Clause "New" or "Revised" License
6.23k stars 817 forks source link

Bug creating foreign key #1766

Closed elmanueh closed 8 months ago

elmanueh commented 8 months ago

Issue Summary

Im trying to create this 2 tables in my database. When its created and i see the structure of the table, i check thats its incorrect.

CREATE TABLE IF NOT EXISTS ClanData (
    tag                 TEXT    NOT NULL,
    PRIMARY KEY (tag)
);

CREATE TABLE IF NOT EXISTS PlayerData (
    clan                TEXT    NOT NULL,
    tag                 TEXT    NOT NULL,
    PRIMARY KEY (clan, tag),
    FOREIGN KEY (clan) REFERENCES ClanData(tag)
        ON DELETE CASCADE
        ON UPDATE CASCADE
);

image

The foreign key its asigning in the tag of the table PlayerData and not in clan. I dont know why its happend it. Before create the tables, pragma foreign key its beeing activated.

Steps to Reproduce

  1. Create the first table
  2. Create the second table
  3. Check if foreign key its realized good. (not it is)

Version

5.1.7

Node.js Version

18.16.1

How did you install the library?

W10 x64