Im trying execute laravel migration to create pivot table. I've two models which are defined in relation many to many. Below is method to migration
public function up() {
Schema::create('api_user', function (Blueprint $table) {
$table->increments('id');
$table->integer('api_id')->unsigned()->index();
$table->foreign('api_id')->references('id')->on('apis')->onDelete('cascade');
$table->uuid('user_uid')->unsigned()->index();
$table->foreign('user_uid')->references('uid')->on('users')->onDelete('cascade');
$table->timestamps();
});
}
After execute php artisan migrate , I received sql error
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'unsigned not null, `created_at` timestamp null, `updated_at` timestamp null) def' at line 1 (SQL: create table `api_user` (`id` int unsigned not null auto_increment primary key, `api_id` int unsigned not null, `user_uid` char(36) unsigned not null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
Uuid is storing as varch in DB. Perhaps varchart cannot set as unsigned attribute. Is anothoer way to create pivot table from migration except Laravel-5-Generators-Extended.?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire