tj / node-migrate

Abstract migration framework for node
MIT License
1.54k stars 224 forks source link

foreign key invalid sql syntax #165

Closed JamesZEMOURI closed 4 years ago

JamesZEMOURI commented 4 years ago
  await db.createTable('history', {
    id: {
      type: 'int',
      primaryKey: true,
      notNull: true,
      autoIncrement: true,
      length: 11
    },
    status: {
      type: 'int',
      length: 1
    },
    descri: 'string',
    date: 'date',
    token: {
      type: 'string',
      notNull: true,
      foreignKey: {
        name: 'blablou',
        table: 'tokens',
        rules: {
          onDelete: 'RESTRICT',
          onUpdate: 'RESTRICT'
        },
        mapping: 'token'
      }
    },
  });

give me :

ALTER TABLE `history` ADD CONSTRAINT `blablou` FOREIGN KEY ([ '`token`' ]) REFERENCES `tokens` ([ '`token`' ]) ON DELETE RESTRICT ON UPDATE RESTRICT

should be :

 ALTER TABLE `history` ADD CONSTRAINT `blablou` FOREIGN KEY (token) REFERENCES `tokens` (token) ON DELETE RESTRICT ON UPDATE RESTRICT
wesleytodd commented 4 years ago

Hi @JamesZEMOURI, this library does not have any particular support for a type of database or library to access it, so my guess is that you are using some other ORM library along with migrate. I would figure out which that is and post this question on that repo. good luck!