First Check
Commit to Help
Example Code
class Foo(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
bar: str
Description
- Create model, with id field as described in docs
- Run alembic migrations
- Upgrade head
- Run alembic migrations again
Alembic reads the primary key as nullable.
When running second time it tries to alter the field
You will then get an error when trying to upgrade.
I using psycopg2-binary
*Adding nullable=False to id declaration fixes this. Should this be added to the tutorial?
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
3.8
Additional Context
"""foo
Revision ID: 6d4a123a9ff6
Revises: 2910ce9e323e
Create Date: 2021-10-01 12:53:59.432921
"""
from alembic import op
import sqlalchemy as sa
import sqlmodel
revision identifiers, used by Alembic.
revision = '6d4a123a9ff6'
down_revision = '2910ce9e323e'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('foo',
sa.Column('id', sa.Integer(), nullable=True),
sa.Column('bar', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_foo_bar'), 'foo', ['bar'], unique=False)
op.create_index(op.f('ix_foo_id'), 'foo', ['id'], unique=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_foo_id'), table_name='foo')
op.drop_index(op.f('ix_foo_bar'), table_name='foo')
op.drop_table('foo')
# ### end Alembic commands ###
First Check
Commit to Help
Example Code
Description
Alembic reads the primary key as nullable.
When running second time it tries to alter the field
You will then get an error when trying to upgrade.
I using psycopg2-binary
*Adding nullable=False to id declaration fixes this. Should this be added to the tutorial?
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
3.8
Additional Context
"""foo
Revision ID: 6d4a123a9ff6
Revises: 2910ce9e323e
Create Date: 2021-10-01 12:53:59.432921
"""
from alembic import op
import sqlalchemy as sa
import sqlmodel
revision identifiers, used by Alembic.
revision = '6d4a123a9ff6'
down_revision = '2910ce9e323e'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('foo',
sa.Column('id', sa.Integer(), nullable=True),
sa.Column('bar', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_foo_bar'), 'foo', ['bar'], unique=False)
op.create_index(op.f('ix_foo_id'), 'foo', ['id'], unique=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_foo_id'), table_name='foo')
op.drop_index(op.f('ix_foo_bar'), table_name='foo')
op.drop_table('foo')
# ### end Alembic commands ###