I tried to issue
$ php artisan db:seed
Seeding: RoleSeeder
In Connection.php line 664:
SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table referenced in a foreign key constraint (
news.users, CONST RAINTusers_role_id_foreignFOREIGN KEY (role_id) REFERENCESnews.roles(id)) (SQL: truncateroles)
This is my Roleseeder.php file
<?php
use Illuminate\Database\Seeder;
use App\Role ;
class RoleSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Role::truncate();
Role::create([
'title' => 'Students',
'description' => 'Lorem ipsum dolor.'
]);
// ....
I don't understand why I get that error ..
I have this migration file
Schema::table('users', function (Blueprint $table) {
$table->integer('role_id')->unsigned()->after("id")->nullable();
$table->foreign('role_id')
->references('id')->on('roles')
->onDelete('restrict');
});