so I use my project locally and run this code php artisan migrateeverything works fine and my tables will be created
but when I go to my vps and do the same, I get this error
[Lighten \ Database \ QueryException] SQLSTATE [HY000]: general error: 1215 Unable to add foreign key constraint (SQL: alter table mediablesadd mediables_media_id_foreignforei gn constraint key ( media_id) refers to media( id) deletion of the cascade)
I followed some solution from this site, but they did not work
my migration file:
Schema::create('media', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->nullable();
$table->string('old_name')->nullable();
$table->text('desc')->nullable();
$table->string('category')->nullable();
$table->string('type');
$table->string('format');
$table->string('href');
$table->string('thumbnail')->nullable();
$table->timestamps();
});
Schema::create('mediables', function (Blueprint $table) {
$table->integer('media_id')->nullable();
$table->integer('mediable_id');
$table->string('mediable_type');
$table->primary(['media_id','mediable_id','mediable_type']);
$table->timestamps();
});
Schema::table('mediables', function (Blueprint $table) {
$table->foreign('media_id')
->references('id')->on('media')
->onDelete('cascade');
});
note that in my project there is a polymorphic relationship between the media and other models
vps , apache nginx vps,