Skip to content
This repository has been archived by the owner on Aug 17, 2019. It is now read-only.

php artisan db:seed #2

Open
sxdubin opened this issue Jul 18, 2017 · 2 comments
Open

php artisan db:seed #2

sxdubin opened this issue Jul 18, 2017 · 2 comments

Comments

@sxdubin
Copy link

sxdubin commented Jul 18, 2017

vagrant@homestead:~/work/admin$ php artisan db:seed
Seeded: UserTableSeeder
Seeded: PermissionTableSeeder

[Illuminate\Database\QueryException]
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (homestead.role_admin, CONSTRAINT role_admin_user_id_foreign FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE) (SQL: insert into role_admin (role_id, user_id) values (2, 2))

[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (homestead.role_admin, CONSTRAINT role_admin_user_id_foreign FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE)

@jwwb681232
Copy link
Owner

jwwb681232 commented Jul 18, 2017

Please delete all data tables before running

composer dump-autoload
php artisan migrate --seed

@sxdubin
Copy link
Author

sxdubin commented Jul 18, 2017

vagrant@homestead:~/work/admin$ php artisan db:seed
Seeded: UserTableSeeder
Seeded: PermissionTableSeeder

[Illuminate\Database\QueryException]
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (homestead.role_admin, CONSTRAINT role_admin_user_id_foreign FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE) (SQL: insert into role_admin (role_id, user_id) values (2, 2))

[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (homestead.role_admin, CONSTRAINT role_admin_user_id_foreign FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE ON UPDATE CASCADE)

Error:

 (SQL: insert into role_admin (role_id, user_id) values (2, 2))

Solution:

Add into /yourproject/database/seeds/UserTableSeeder.php

        User::create([
            'name' => 'UserName2',
            'email' => '[email protected]',
            'password' => 'username2',
        ]);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants