Skip to content
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

Failed to insert row with only default values #420

Closed
Crypto-Virus opened this issue Jan 4, 2022 · 1 comment · Fixed by #432 or #589
Closed

Failed to insert row with only default values #420

Crypto-Virus opened this issue Jan 4, 2022 · 1 comment · Fixed by #432 or #589
Assignees
Milestone

Comments

@Crypto-Virus
Copy link

Invalid SQL query is generated when inserting into a table that has default values for all columns.

e.g.

When inserting into below table

CREATE TABLE topics (
    id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
);

with this rust code

let topic = topics::ActiveModel { ..Default::default() };
topic.insert(db).await?;

returns this error
DbErr(Query("error returned from database: syntax error at or near \")\""))

because below query is generated
INSERT INTO "topics" () VALUES () RETURNING "id"

@billy1624
Copy link
Member

billy1624 commented Jan 4, 2022

Hey @Crypto-Virus, welcome and thanks for the report!

For insert statement without specifying columns & values it should generate

INSERT INTO "topics" DEFAULT VALUES RETURNING "id"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants