it looks at tables in the db not previous migrations. The error message you see is direct from the database rather than what Laravel thinks is an issue
Failed to open referenced table
I have got an error:
SQLSTATE[HY000]: General error: 1824 Failed to open the referenced table 'regions' (SQL: alter table `gantt_chart_templates` add constraint `gantt_chart_templates_region_id_foreign` foreign key (`region_id`) references `regions` (`id`) on delete cascade)
It is saying it can't find the tables, however, the table is there. But, it seems the table wasn't created using migration before. Could it be the reason? Or there should be no issue as long as the table is there?
My migration is:
Schema::connection('mysql')->create('gantt_chart_templates', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('project_types');
$table->unsignedInteger('region_id');
$table->foreign('region_id')->references('id')->on('regions')->onDelete('cascade');
$table->timestamps();
});
@Inquisitive Yes, perfectly safe. The differences between the two are only really to do with what features they support – the data itself is the same (or samey enough that it can be easily converted back and forth without problems). The key differences are:
- InnoDB supports foreign keys, transactions; MyISAM does not
- InnoDB does row-locking (queries lock only affected rows, so other queries can run concurrently on the same table; MyISAM does table-locking (queries lock the entire table)
- InnoDB uses transactional logs and other means to prevent or fix data corruption or loss; MyISAM doesn’t do anything to secure data integrity
- MyISAM has always supported full-text indexing; InnoDB did not until MySQL 5.6.4.
(With help from this ServerFault answer for a lot of the details.)
The MySQL website has a long and detailed list of things to look out for when migrating a table from MyISAM to InnoDB. As always, their docs are very verbose, but it’s probably a good idea to have a look through it and see if any of the caveats apply to your table.
Please or to participate in this conversation.