I have two tables like User and Roles . i want to added foreign Roles_id on Table Users .
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('NIK',16);
$table->string('nama');
$table->string('email')->unique();
$table->string('username');
$table->string('password');
$table->unsignedBigInteger('roles_id')->default(1);
$table->timestamps();
$table->softDeletes();
$table->foreign('roles_id')->references('id')->on('roles');
});
}
and my roles table
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('roles');
$table->timestamps();
});
}
iam not catching the miss code , i using unsignedBigInteger , ann still error . i am using -> nullable . but didnt work . can somone find this error ?
edit . this error :
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table
users
add constraintusers_roles_id_foreign
foreign key (roles_id
) referencesroles
(id
))