Support the ongoing development of Laravel.io →
posted 10 years ago
Database
Last updated 1 year ago.
0

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');
Last updated 1 year ago.
0

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

Last updated 1 year ago.
0

any idea?

Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

pajooh pajooh Joined 15 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.