BillingTrack
BillingTrack copied to clipboard
Inconsistent database engine result in failed FK creation
Receiving the following error during initial migration usingphp artisan migrate:fresh --seed
or visit your.site.com/setup
[Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 1005 Can't create table xxx.#clients (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table 'clients' add constraint 'clients_industry_id_foreign' foreign key ('industry_id') references 'industries' ('id') on delete no action on update no action)
To Reproduce Steps to reproduce the behavior:
- clone project
- run through setup instruction
.env
file, database creation, etc.... - finally run
php artisan migrate:fresh --seed
or visityour.site.com/setup
Expected behavior Should not error.
Desktop/Smartphone: Should not matter.
Additional context
Issue is due to database engine difference between clients
InnoDB and industries
MyISAM table.
Instead of manually define database engine everywhere, I recommend to define it at the global/configuration area? https://github.com/cytech/BillingTrack/blob/master/config/database.php#L25
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => env('DB_STRICT', false),
'engine' => 'innodb',
//'charset' => 'utf8',
//'collation' => 'utf8_unicode_ci',
],