2

Problem is at the time of migration my child tables created at first and it could not find parents table and not able to assign the foreign key of parent table primary key and i get the error as below.

here warehouses is children and the companies is parent

at Runner. (/Volumes/DATA/paras/adonis-js/smart-helmet-backend/smarthelmet/node_modules/knex/lib/runner.js:213:19) code: 'ER_FK_CANNOT_OPEN_PARENT', errno: 1824, sqlMessage: 'Failed to open the referenced table \'companies\'', sqlState: 'HY000',
index: 0, sql: 'alter table warehouses add constraint warehouses_company_id_foreign foreign key (company_id) references companies (id)' }

paras shah
  • 861
  • 2
  • 9
  • 23

1 Answers1

4

you can change the migration file name.

  • migration file name is unique this create file name using date so you can copy your child file numeric name and then replace parent file name numeric data and decrease number by one of your parent file
  • if child filename 1503250034280_token.js and prent file name 1565022160220_email_schema.js like this then change parent name like this 1503250034279_email_schema.js then you run migration it's work
Amit Kadivar
  • 798
  • 4
  • 12