Astrotomic / laravel-translatable

A Laravel package for multilingual models
https://docs.astrotomic.info/laravel-translatable/
MIT License
1.23k stars 155 forks source link

Update documentation #281

Closed ligoo closed 2 years ago

ligoo commented 2 years ago

In the migration guide you have this:

Schema::create('post_translations', function(Blueprint $table) {
    $table->increments('id');
    $table->integer('post_id')->unsigned();
    $table->string('locale')->index();
    $table->string('title');
    $table->text('content');

    $table->unique(['post_id', 'locale']);
    $table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade');

When using Laravel 9.x with mysql I had the error:

SQLSTATE[HY000]: General error: 3780 Referencing column 'post_id' and referenced column 'id' in foreign key constraint 'post_translations_post_id_foreign' are incompatible. (SQL: alter table `post_translations` add constraint `post_translations_post_id_foreign` foreign key (`post_id`) references `posts` (`id`) on delete cascade)

This is because the the structure and data type of the primary key and foreign key must be same.

Solution:

$table->unsignedBigInteger('post_id');

EDIT: This is because I had $table->id() (default when making a new migration file) instead of $table->increments('id') I think. Maybe a warning notice in the doc would be enough though.

MateooS commented 2 years ago

Yeah..

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days