Fix SQL migration error
This commit is contained in:
@@ -11,6 +11,9 @@ After editing `src/pirats/models.py`, generate a migration and sanity-check it:
|
|||||||
.venv/bin/alembic upgrade head # or just start the app
|
.venv/bin/alembic upgrade head # or just start the app
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Note on adding NOT NULL columns in SQLite:**
|
||||||
|
SQLite does not support adding a `NOT NULL` column without a default value to an existing table. When Alembic auto-generates a migration that adds a `nullable=False` column, you MUST manually edit the migration to include `server_default="..."` in the `sa.Column` definition (e.g., `server_default=""` for strings) before applying it. Otherwise, the migration will crash with `Cannot add a NOT NULL column with default value NULL`.
|
||||||
|
|
||||||
Do NOT add ad-hoc `ALTER TABLE` statements to `database.py` — that legacy list exists only to upgrade pre-Alembic databases to the baseline and must not grow.
|
Do NOT add ad-hoc `ALTER TABLE` statements to `database.py` — that legacy list exists only to upgrade pre-Alembic databases to the baseline and must not grow.
|
||||||
|
|
||||||
## Learning during testing
|
## Learning during testing
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ depends_on = None
|
|||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
with op.batch_alter_table('challenge', schema=None) as batch_op:
|
with op.batch_alter_table('challenge', schema=None) as batch_op:
|
||||||
batch_op.add_column(sa.Column('stakes_success', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
|
batch_op.add_column(sa.Column('stakes_success', sqlmodel.sql.sqltypes.AutoString(), server_default="", nullable=False))
|
||||||
batch_op.add_column(sa.Column('stakes_failure', sqlmodel.sql.sqltypes.AutoString(), nullable=False))
|
batch_op.add_column(sa.Column('stakes_failure', sqlmodel.sql.sqltypes.AutoString(), server_default="", nullable=False))
|
||||||
|
|
||||||
# ### end Alembic commands ###
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user