I want to create a foreign key that is string from table "stocks" to "rfids". The two tables are shown below. stocks table:
Schema::create('stocks', function (Blueprint $table) {
$table->increments('tag_no');
$table->string('stock_type');
$table->string('rfid');
$table->foreign('rfid')->references('RFID_UID')->on('rfids');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
rfids table:
Schema::create('rfids', function (Blueprint $table) {
$table->increments('id');
$table->string('RFID_UID');
$table->timestamps();
});
When i use php artisan migrate it shows error.
SQLSTATE[HY000]: General error: 1005 Can't create table hardware
.#sql-81c_c8
(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table stocks
add constraint stocks_rfid_foreign
foreign key (rfid
) references rfids
(RFID_UID
))
Someone help me pls!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire