Facing error : SQLSTATE[23000]: Integrity constraint violation: 1452 Hi I am trying to save data to the table but fail as I am facing an error while executing save() and I am creating one to many relationship.
Relationship defined in Blog model :
in User model:
users table:
blogs table:
blogs controller:
Please tell me whats wrong I have no idea .
Thank You.
What order are your migrations run in? Do you have the relevant rows in your database? Also, you have pasted your create_blogs_table migration twice instead of your BlogController .
When I run php artisan migrate:refresh this is the order
It means you don't have any users in your database. You need to insert a user before you can reference them.
Add say 10 users first, then try to add blog posts, you'll see that it works :)
Oh sorry I did not realize that there were no user created. Thank you so much @mstnorris
@eddy1992 it is an easy mistake to make, but, now you know what that error usually means so you won't make that mistake again :)
Please sign in or create an account to participate in this conversation.