I think only you can do is entirely turn off constraint checks temporarily.
<?php
DB::statement('SET FOREIGN_KEY_CHECKS=0');
// insert stuff
DB::statement('SET FOREIGN_KEY_CHECKS=1');
turning off constraint (via FOREIGN_KEY_CHECKS) is mysql specific, also, this will not force constraint checking any time later so, some foreign keys may be invalid and no way to know that
i want to use postgresql, as it supports DEFERRABLE constraint checking
Correct me if I'm wrong, but for me it seems your problem is not when creating the table but populating a lot of data into it. So, it's not about migration but seeding.
If that's the case, and you have a really huge amount of data, prefer loading it via LOAD DATA LOCAL INFILE using data from a csv file...
http://dev.mysql.com/doc/refman/5.5/en/load-data.html
You can issue it from a raw query. It performs as a charm, once this resource is designed for this purpose, works with all engines. The only performance issue is when inserting lots of data in partitioned myisam tables, because they have a table-level locking (which turns into partition-level locking). For engines like innodb, which have row-level locking, it's very fast, and it does not perform any checks prior finishing the process.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community