You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've got two tables, one called users and one called posts. In the posts table i've got a foreign key to the id of the users table and i've defined one to many relationship between User and Post.
My problem is the following: can't create a Post in the database because the column user_id (the foreign key) doesn't have a default value.
First i create a User with the following function:
defcreate_user(name):
returnUser.create({'name': name})
# Executing it like this:new_user=create_user('John')
After that i try to create a Post:
defcreate_post(user, title):
returnPost.create({'title': title, 'user_id': user.id})
# Executing it like this:new_post=create_post(new_user, 'Hello World')
When executing the second function i get the following error:
masoniteorm.exceptions.QueryException: (1364, "Field 'user_id' doesn't have a default value")
I've used Eloquent in the past but in php and i don't know how to translate to python the following code:
I've got two tables, one called
users
and one calledposts
. In theposts
table i've got a foreign key to the id of theusers
table and i've defined one to many relationship betweenUser
andPost
.My problem is the following: can't create a
Post
in the database because the columnuser_id
(the foreign key) doesn't have a default value.First i create a
User
with the following function:After that i try to create a
Post
:When executing the second function i get the following error:
I've used Eloquent in the past but in php and i don't know how to translate to python the following code:
I've tried the following without success (even without the parenthesis after
post
):This may seem a stupid hiccup to some but couldn't find anything in the documentation unfortunatelly.
Thanks in advance for the help.
The text was updated successfully, but these errors were encountered: