We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Describe the bug Bulk creation with on_conflict set to primary key works for IntField PKs. After switching to CharField it fails with:
tortoise.exceptions.OperationalError: ON CONFLICT clause does not match any PRIMARY KEY or UNIQUE constraint
To Reproduce
class Tournament(Model): # id = fields.IntField(primary_key=True) id = fields.CharField(primary_key=True, max_length=48) field1 = fields.CharField(max_length=10) async def run(): await Tortoise.init(db_url=f"sqlite://:memory:", modules={"models": ["__main__"]}) await Tortoise.generate_schemas() await Tournament.bulk_create([Tournament(id="123", field1="Some value")], update_fields=["id", "field1"], on_conflict=["id"])
Expected behavior Bulk creation works with CharField PK as well.
Additional context Generated SQL / Debug output:
2024-09-28 13:53:47 - tortoise.db_client:84 - DEBUG - Created connection <Connection(Thread-1, started 139755117758144)> with params: filename=:memory: journal_mode=WAL journal_size_limit=16384 foreign_keys=ON 2024-09-28 13:53:47 - tortoise.db_client:164 - DEBUG - CREATE TABLE IF NOT EXISTS "tournament" ( "id" VARCHAR(48) NOT NULL PRIMARY KEY, "field1" VARCHAR(10) NOT NULL ); 2024-09-28 13:53:47 - tortoise.db_client:132 - DEBUG - INSERT INTO "tournament" ("id","field1") VALUES (?,?) ON CONFLICT ("id", "id") DO UPDATE SET "id"=EXCLUDED."id","id"=EXCLUDED."id","field1"=EXCLUDED."field1","field1"=EXCLUDED."field1": [['123', 'Some value']] 2024-09-28 13:53:47 - tortoise.db_client:94 - DEBUG - Closed connection <Connection(Thread-1, started 139755117758144)> with params: filename=:memory: journal_mode=WAL journal_size_limit=16384 foreign_keys=ON
The text was updated successfully, but these errors were encountered:
Hey @lnxsr, this is caused by a bug in pypika-tortoise. I just submitted a PR which should fix the issue tortoise/pypika-tortoise#14
Sorry, something went wrong.
Successfully merging a pull request may close this issue.
Describe the bug
Bulk creation with on_conflict set to primary key works for IntField PKs.
After switching to CharField it fails with:
tortoise.exceptions.OperationalError: ON CONFLICT clause does not match any PRIMARY KEY or UNIQUE constraint
To Reproduce
Expected behavior
Bulk creation works with CharField PK as well.
Additional context
Generated SQL / Debug output:
The text was updated successfully, but these errors were encountered: