New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Primary key field not being added to any queries #143
Comments
Just to be clear, what's the schema of the table? How do you create the table? |
|
Thanks for the input. Did you use |
Yep. |
I just changed the
|
Doesn't look like its an issue with the generated schema with BIGINT as pk type (no effect)
|
A few points here: When using the And for the
I think the error you mentioned of unstable auto increment is explained here, Anyways please try again with the Integer and see if it solves your issue. |
Oh my bad, I thought sqlite made all primary keys non-nullalbe (coming from postgres which seemed to do the same thing)
|
I retract my statement. Instead of inserting the actual data, it just autoincremented the id column again. (Just to clarify, the value I'm passing to |
Yeah, I think that's done by decision. You shouldn't pass the primary key to the query. You either set on on python-side by specifying a default like this: Lines 45 to 53 in c6b9c0e
Or by letting the database to set it: Lines 28 to 42 in c6b9c0e
|
Wait.. so can I not specify my own primary key value? does it have to be decided by the db/ |
Yeah, it's removed here https://github.com/encode/orm/blob/master/orm/models.py#L402 I'm just saying this is expected, if you find maybe Django or SQLAlchemy have a different behaviour, we could change it. |
Ah I see, just a misunderstanding on my part then 😅 Thanks again |
Checklist
master
.Describe the bug
Despite the column
id
(the table's primary key) being included in queries explicitly via the name (id=
), and via implicit (pk=
), the same result is still yielded.I don't know what could be causing this as I've been using encode/orm since 0.2 and its worked fine, up until this one god forsaken project.
To reproduce
I'm honestly not too sure what's causing this so im going to provide my table, the queries I'm making, and some example data
Expected behavior
An entry is correctly created
Actual behavior
Sometimes (unclear why) the
id
field autoincrements itself(???), or (more often than not) the code errors out with a not null constraint failureDebugging material
Notable tracebacks:
Traceback from console
From debug logs (via `logging` module):
Traceback from web debugger
Environment
Linux (me)-laptop 5.14.21-2-MANJARO #1 SMP PREEMPT Sun Nov 21 22:43:47 UTC 2021 x86_64 GNU/Linux
)The text was updated successfully, but these errors were encountered: