0
votes

I'm trying to create DB in SQLite. The file is creating as I wish to, but I got an exception from title above (reminder: SQLSTATE[HY000]: General error: 1 near "action": syntax error). I have no idea why I got it.

$Database->exec(

"



CREATE TABLE unit (

    unit_id INTEGER PRIMARY KEY AUTOINCREMENT,

    NAME VARCHAR(30) NOT NULL,

    unitsize VARCHAR(2) NOT NULL,

    line INTEGER(3) NOT NULL,

    MMR INTEGER(10) NOT NULL,

    lastin TIMESTAMP,

    lifespan INTEGER(4) NOT NULL,

    consumption INTEGER(3) NOT NULL

    );



    CREATE TABLE workshop (

    workid INTEGER PRIMARY KEY AUTOINCREMENT,

    unit_id INTEGER NOT NULL,

    fk_unit INTEGER,

    FOREIGN KEY(fk_unit) REFERENCES unit(unit_id),

    action VARCHAR,

    com TEXT,

    date TIMESTAMP

    );



    CREATE TABLE movement (

    move_id INTEGER PRIMARY KEY AUTOINCREMENT,

    unit_id INTEGER NOT NULL,

    fk_id INTEGER,

    FOREIGN KEY(fk_id) REFERENCES unit(unit_id),

    line VARCHAR(10),

    in_out INTEGER(1), 

    akcja VARCHAR,

    com VARCHAR,

    DATE TIMESTAMP

    );



      ");

EDIT: It seems like a problem with TEXT/VARCHAR datatype. Any idea why?

1
did you missed VARCHAR(100) ?Shan

1 Answers

1
votes

Table constraints such as FOREIGN KEY(fk_unit) REFERENCES unit(unit_id) should follow column specifications. You now have the table constraint in the middle of your columns specs. Move it to the end of your CREATE TABLE.