Search code examples
mysqlsqlsyntaxmysql-error-1064

sql Error 1064 (42000) Syntax Error


CREATE TABLE IF NOT EXISTS message(
  id INT NOT NULL auto_increment,
  userid INT NOT NULL,
  date Date NOT NULL,
  text varchar(255) NOT NULL,
  PRIMARY KEY  ('id')
  FOREIGN KEY ('userid') REFERENCES users('id'));

I was just wondering if someone could help me in identifying a syntax error as I can not create a table.


Solution

  • Try to put , after the primary key declaration.

    Update: I guess it should be

    CREATE TABLE IF NOT EXISTS message (
      id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
      userid INT NOT NULL,
      date Date NOT NULL,
      text varchar(255) NOT NULL,
      FOREIGN KEY (userid) REFERENCES users(id));