Open
Description
An error occurs when trying to migrate:
tortoise.exceptions.OperationalError: Cannot add a NOT NULL column with default value NULL
My code:
class MyModel(Model):
temp_notification = JSONField(default={'by_username': {},
'users': {}}, null=False)
Migrate code:
async def upgrade(db: BaseDBAsyncClient) -> str:
return """
ALTER TABLE "guilds" ADD "temp_notification" JSON NOT NULL;"""
The correct migration:
async def upgrade(db: BaseDBAsyncClient) -> str:
return """
ALTER TABLE "guilds" ADD "temp_notification" JSON NOT NULL DEFAULT '{"by_username": {}, "users": {}}';"""
In this case, the upgrade is successful.
I've already seen a similar error, it seems like I've already installed the latest version, but it still doesn't help.
Metadata
Metadata
Assignees
Labels
No labels