- 
                Notifications
    
You must be signed in to change notification settings  - Fork 11.6k
 
Closed
Description
- Laravel Version: 10.0.3
 - PHP Version: 8.2.3
 - Database Driver & Version: MySQL 8.0.32
 
Description:
The foreignIdFor method when used with a bigInt primary key that is not AUTO INCREMENT produces a column of type char in the database, so the constraint does not work correctly.
Probably the error happens due to validation of the value of incrementing inside the method:
Steps To Reproduce:
- Creates a main migration and sets 
unsignedBigIntegerandprimary: 
Schema::create('my_tables', function (Blueprint $table) {
    $table->unsignedBigInteger('id')->primary();
    $table->string('some_another_field');        
    $table->timestamps();        
});- Create a second migration and adds 
foreignIdFor. 
Schema::create('your_tables', function (Blueprint $table) {
    $table->foreignIdFor(MyTable::class)->constrained();
    $table->string('another_field');        
    $table->timestamps();
});- 
Define
public $incrementing = false;inMyTablemodel class. - 
Runs
php artisan migrateorphp artisan migrate:freshto verify error: 
Referencing column 'my_table_id' and referenced column 'id' in foreign key constraint 
'your_tables_my_table_id_foreign' are incompatible.
clementmas, billyonecan and pfried
Metadata
Metadata
Assignees
Labels
No labels
