Skip to content

Aerich does not set default values during migration #442

Description

@lordcod

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions