vanilophp / framework

The truly Laravel E-commerce Framework
https://vanilo.io
MIT License
810 stars 102 forks source link

Foreign key constraint is incorrectly formed on fresh installation #42

Closed Sohib closed 5 years ago

Sohib commented 5 years ago

i'm following the installation instruction but i have encountered this issue twice, when running php artisan migrate

i get this error message

Migrating: 2016_12_18_121118_create_profiles_table

   Illuminate\Database\QueryException  : SQLSTATE[HY000]: General error: 1005 Can't create table `vanilo`.`#sql-9a5_a6` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `profiles` add constraint `profiles_user_id_foreign` foreign key (`user_id`) references `users` (`id`))

  at vaniloapp/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668| 

  Exception trace:

  1   PDOException::("SQLSTATE[HY000]: General error: 1005 Can't create table `vanilo`.`#sql-9a5_a6` (errno: 150 "Foreign key constraint is incorrectly formed")")
      vaniloapp/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458

  2   PDOStatement::execute()
      vaniloapp/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458

my database is Server version: 10.2.18-MariaDB - Homebrew

Sohib commented 5 years ago

Laravel version is Laravel Framework 5.8.8

I think i know what caused this issue. Laravel uses $table->bigIncrements('id'); for users table while Vanilo uses the following for foreign keys $table->integer('user_id')->unsigned(); as a normal integer but it should use bigInteger

yusufkandemir commented 5 years ago

This issue is about artkonekt/user package and changes in Laravel 5.8, which is caused by this line.

$table->integer('user_id')->unsigned();

In Laravel 5.8, they changed type of id columns from increments to bigIncrements in create_users_table migration and migration stubs. They state this change in docs as:

Migrations & bigIncrements

Likelihood Of Impact: None

It looks like it actually has impact not because they changed migration stubs but create_users_table migration too.

If the line in artkonekt/user package is changed as follows:

- $table->integer('user_id')->unsigned();
+ $table->bigInteger('user_id')->unsigned();

the problem with Laravel 5.8 will be solved. But then unfortunately this solution will conflict with older Laravel versions.

hamzaSaktan commented 5 years ago

In laravel 5.8 $table->bigIncrements('id'); $table->bigInteger('user_id')->unsigned();

fulopattila122 commented 5 years ago

Version 1.1.0 of the User Module has been released - that fixes this issue.