-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
alembic migrations giving nullable wrongly at times #285
Comments
Note that after a bunch of debugging, through sqla-compat and alembic code (Neither of which I am familiar with - so, I may be seeing the wrong thing :) ) I found: >>> from myapp.models import MyTable
>>> from sqlalchemy_continuum import version_class
>>> MyModel.__table__.c.mycol.nullable
False
>>> version_class(MyModel).__table__.c.mycol.nullable
True
>>> from alembic.util import sqla_compat
>>> sqla_compat._copy(MyModel.__table__.c.mycol).nullable
False
>>> sqla_compat._copy(version_class(MyModel).__table__.c.mycol).nullable
False #### <----- This should have been True? But when I try to reproduce the same issue without sqla-continuum - the nullable is fine: >>> sqla_compat._copy(sa.Column('mycol', nullable=True)).nullable
True #### <----- This seems correct |
Hi @AbdealiJK , Was trying to dig into this issue, it seems it gives nullable = True due to a bug in column replication method in table_builder.column_reflector. Currently it is fixes the issue. EDIT: Not sure if it's a bug or a requirement from SQLA Cont. to have non PK columns as Nullable for version table as i can see there is a testcase covering this specific case |
I don't understand the suggested fix @indiVar0508 In your code:
The nullable is already True. So you aren't changing anything |
Adding the to reproduce the above issue mentioned in thread i created below shown demo model.
and used below mentioned command(s) to generate issue
and after that alembic generated upgrade and downgrade methods post commit
but after adding that condition to add a condn that non-PK col can also have
i might be wrong also here as later i saw that a testcase is there specific for this behavior. version i had while trying to replicate the issue
|
Found that this was happenign because of the https://github.com/sqlalchemy/sqlalchemy/blob/rel_1_4_41/lib/sqlalchemy/sql/schema.py#L2018 |
Apply fix specified in kvesteri#285 (comment)
Apply fix specified in kvesteri#285 (comment)
alembic was generating incorrect nullable for version_tables when generating a migrations script for empty DB, so setting value based on discussion in original issue thread in kvesteri/sqlalchemy-continuum#285 (comment)
alembic was generating incorrect nullable for version_tables when generating a migrations script for empty DB, so setting value based on discussion in original issue thread in kvesteri/sqlalchemy-continuum#285 (comment)
This seems to be a weird issue.
When I add
__versioned__
for the first time to a model and create an alembic migration with:It gives:
Then when I run:
I was expecting it to say "no changes found"
But it does detect changes and is saying that
nullable=True
now:This seems to be consistently reproducible - the first time alembic is generating
nullable=False
. Then second time alembic is generatingnullable=True
Versions I use:
The text was updated successfully, but these errors were encountered: