Open sqlalchemy-bot opened 8 years ago
Michael Bayer (@zzzeek) wrote:
well SQLAlchemy would have to reflect this which I don't believe it does right now. SQLA can accept a pull request to include reflection of this option. sqlite_autoincrement is a rarely used option so the workaround here is not that unreasonable.
Changes by berend (@berend):
Changes by berend (@berend):
Should the autogeneration option in alembic autogenerate the table_kwargs={'sqlite_autoincrement': True}
?
oh this is batch, not autogenerate.
Should the autogeneration option in alembic autogenerate the
table_kwargs={'sqlite_autoincrement': True}
?
this issue regards batch mode for SQLite. i dont understand the question
I was trying to use sqlite_autoincrement
and I realized I had this same issue.
Where when I create a new ORM model:
class ExampleTable(WithoutWorkspace, BaseModel):
__tablename__ = "example_table"
__tableargs__ = {"sqlite_autoincrement": True}
id = Column(BigInteger, primary_key=True)
And then I use alembic's alembic migrate
- it creates:
def upgrade():
op.create_table(
"example_table",
sa.Column("id", sa.BigInteger(), nullable=False),
sa.PrimaryKeyConstraint("id", name=op.f("pk_example_table")),
sqlite_autoincrement=True,
)
Now, I use context.configure(..., render_as_batch=True)
in my env.py
So, when I make a change to a column (let's say I add a column to this table). The generated code is:
def upgrade():
with op.batch_alter_table("example_table", schema=None) as batch_op:
batch_op.add_column(sa.Column("name", sa.String(), nullable=True))
if the recommendation here is to use:
with op.batch_alter_table("example_table", schema=None, table_kwargs={'sqlite_autoincrement': True}) as batch_op
I am wondering if alembic should have generate that for me
batch op when it drops and recreates the table would ideally know about sqlite_autoincrement, however right now it doesn't , so autogenerate should not generate this since the above is a workaround only that would in theory eventually be fixed in batch mode itself.
Migrated issue, originally created by berend (@berend)
Given a sqlite3 table with
__tableargs__ = {'sqlite_autoincrement': True}
and abatch_op
migration touching that table:Model. initial migration
simple migration, making firstname nullable:
With echo-sql on I can see, that the first version of the
person
table hasautoincrement
on theid
column. During the second migration, alembic creates a temp table, because sqlite does not support alter column operations. That temp table does not have theautoincrement
on theid
column. After renaming it toperson
, the autoincrement is goneManually adding table kwargs to the batch_op is a workaround.
Do I have to always use table_kwargs to let alembic know? Or is there a bug when reading the table to create the temp table?