8000 Aerich does not set default values during migration · Issue #442 · tortoise/aerich · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Aerich does not set default values during migration #442
Open
@lordcod

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.

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

      0