igaster / laravel_cities

Find any country/city in the world. Get Long/Lat etc. Deploy geonames.org database localy. Optimized DB tree
MIT License
179 stars 64 forks source link

FOREIGN_KEY_CHECKS #25

Open ninjasitm opened 4 years ago

ninjasitm commented 4 years ago

Getting this error when seeding on PostgreSQL:

SQLSTATE[42704]: Undefined object: 7 ERROR:  unrecognized configuration parameter "foreign_key_checks" (SQL: SET FOREIGN_KEY_CHECKS=1;)

This is caused by:

\DB::statement('SET FOREIGN_KEY_CHECKS=1;');

This is found on line 173 in seedGeoFile.php;

Fortunately Laravel supports:

Schema::disableForeignKeyConstraints();
davidjoan commented 4 years ago

Same issue using test environment with sqlite

testing.ERROR: SQLSTATE[HY000]: General error: 1 near "SET": syntax error (SQL: SET FOREIGN_KEY_CHECKS=1;) {"exception":"[object] (Illuminate\\Database\\QueryException(code: HY000): SQLSTATE[HY000]: General error: 1 near \"SET\": syntax error (SQL: SET FOREIGN_KEY_CHECKS=1;) at /home/runner/work/app1t/app1t/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664, Doctrine\\DBAL\\Driver\\PDOException(code: HY000): SQLSTATE[HY000]: General error: 1 near \"SET\": syntax error at /home/runner/work/app1t/app1t/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:63, PDOException(code: HY000): SQLSTATE[HY000]: General error: 1 near \"SET\": syntax error at /home/runner/work/app1t/app1t/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:61)

Ethan-Rivas commented 4 years ago

You could add a Trait as mentioned here, it helped me: https://laracasts.com/discuss/channels/eloquent/foreign-key-constraints-on-seeding