ho fatto una domanda (Alembic - sqlalchemy initial migration) su come individuare tabelle utilizzandoAlambicco - sqlalchemy non rileva le tabelle esistenti
target_metadata = Base.metadata
per
alembic revision --autogenerate -m "initial migration"
Dopo ho importato i miei modelli di il file env.py sembrava funzionare bene ma non rileva effettivamente le tabelle esistenti, quindi crea un file di migrazione con tutte le tabelle, ad esempio:
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('Brand',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('slug', sa.String(), nullable=True),
sa.Column('date_created', sa.DateTime(), nullable=True),
sa.Column('date_updated', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id'),
schema='Products'
)
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_table('ProductFile', schema='Products')
ho provato:
alembic stamp head
ma dopo l'esecuzione di questo e in esecuzione autogenerate comando il sistema genera tutti i modelli ancora una volta.
from project.apps.users.models import *
from project.apps.orders.models import *
from project.apps.products.models import *
from project.base import Base, metadata
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
target_metadata = Base.metadata
Come evitare questo problema?
Edit:
ENV.py:
https://gist.github.com/pypetey/bb65807ce773d8baeaf1
ho lasciato cadere il db ed ho fatto funzionare una migrazione
(env) D:\projekty\test>alembic revision --autogenerate
INFO [alembic.migration] Context impl MSSQLImpl.
INFO [alembic.migration] Will assume transactional DDL.
INFO [alembic.autogenerate.compare] Detected added table u'Users.Country'
INFO [alembic.autogenerate.compare] Detected added table u'Products.Brand'
INFO [alembic.autogenerate.compare] Detected added table u'Users.User'
INFO [alembic.autogenerate.compare] Detected added table u'Products.Product'
INFO [alembic.autogenerate.compare] Detected added table u'Products.ProductFile
'
INFO [alembic.autogenerate.compare] Detected added table u'Orders.Order'
INFO [alembic.autogenerate.compare] Detected added table u'Products.Category'
INFO [alembic.autogenerate.compare] Detected added table u'Products.Review'
INFO [alembic.autogenerate.compare] Detected added table u'Users.UserAddress'
INFO [alembic.autogenerate.compare] Detected added table u'Orders.OrderItem'
INFO [alembic.autogenerate.compare] Detected added table u'Orders.OrderStatus'
Generating D:\projekty\test\alembic\versions\1c6337c144a7_.py ... done
(env) D:\projekty\test>alembic upgrade head
INFO [alembic.migration] Context impl MSSQLImpl.
INFO [alembic.migration] Will assume transactional DDL.
INFO [alembic.migration] Running upgrade None -> 1c6337c144a7, empty message
(env) D:\projekty\test>alembic revision --autogenerate
INFO [alembic.migration] Context impl MSSQLImpl.
INFO [alembic.migration] Will assume transactional DDL.
INFO [alembic.autogenerate.compare] Detected added table u'Users.Country'
INFO [alembic.autogenerate.compare] Detected added table u'Products.Brand'
INFO [alembic.autogenerate.compare] Detected added table u'Users.User'
INFO [alembic.autogenerate.compare] Detected added table u'Products.Product'
INFO [alembic.autogenerate.compare] Detected added table u'Products.ProductFile
'
INFO [alembic.autogenerate.compare] Detected added table u'Orders.Order'
INFO [alembic.autogenerate.compare] Detected added table u'Products.Category'
INFO [alembic.autogenerate.compare] Detected added table u'Products.Review'
INFO [alembic.autogenerate.compare] Detected added table u'Users.UserAddress'
INFO [alembic.autogenerate.compare] Detected added table u'Orders.OrderItem'
INFO [alembic.autogenerate.compare] Detected added table u'Orders.OrderStatus'
Generating D:\projekty\test\alembic\versions\5abb204549f_.py ... done
Cosa restituisce "corrente alambicco"? – dgilland
Hai provato a eseguire prima la migrazione su un database vuoto? Dite eseguendo 'alembic revision --autogenerate ...', modificando il file di migrazione, se necessario, eseguendo 'alembic upgrade head', ed eseguendo' alembic revision --autogenerate ... 'di nuovo per confermare che viene generato un file di migrazione vuoto? – dgilland
@dgilland Ho crecreated il db, ho eseguito la migrazione e ho eseguito di nuovo l'autogenerazione. Non ha aiutato. Controlla il mio post aggiornato. – Efrin