![]() ![]() UNIQUE KEY `vendor_product_types_magento_categories_uq` (`vendor_product_type_id`,`magento_category_id`,`sequence`), `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `magento_category_id` bigint(20) unsigned NOT NULL, `vendor_product_type_id` bigint(20) unsigned NOT NULL, `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, ![]() here's the DDL for the table as it exists in MySQL: CREATE TABLE `vendor_product_types_magento_categories` ( 'vendor_product_types_magento_categories', In the downgrade method: op.create_index( Table_name='vendor_product_types_magento_categories' Here's the pertinent part of what is in the upgrade method: op.drop_index( Plus, if I don't reconcile the class to the database this will likely come up every time I auto-generate migrations. I'm completely at a loss as to why the migration is continually trying to drop and re-create this index, which, if I leave in the migration I'll wager is going to fail anyway. I've gotten to the point where Alembic is comparing existing objects in the database against the declarative classes I've made, and there's one pesky index (for a foreign key) that Alembic refuses to leave in-place in my initial migration. Table('mytablewithnopk', tadata, Column(.), Column(.Total newbie to Alembic, SQLAlchemy, and Python. So here, if you're looking for "autogenerate" to pick up on a table that's in your MetaData, and it's not an ORM mapped table, you'd use Table: With Alembic, you define the creation of new tables in a migration script using the create_table() directive: Note that the mapping can be handed a list of Column objects which comprise the primary key even without the primary_key=True flag being present on those columns. an ORM mapped table requires a primary key - background on that is here. > : Mapper Mapper|Test2|test2 could not assemble any primary key columns for mapped table 'test2' ![]() > File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/mapper.py", line 767, in _configure_pks > File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/mapper.py", line 203, in _init_ > return Mapper(class_, local_table, *args, **params) > File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/_init_.py", line 1129, in mapper When I run 'alembic revision -autogenerate' to create migration script, and got below error: > You can see that Test2 is a table without a primary key. > fid = Column(Integer, ForeignKey(' test1.id')) > id = Column(Integer, primary_key = True) > I have 2 simple tables defined as below: On Dec 1, 2012, at 11:49 AM, junepeach wrote: Non-primary key is not good design, but acceptable in mysql, sqlite, postgresql. So I wonder how to create a migration script for a table without primary key. : Mapper Mapper|Test2|test2 could not assemble any primary key columns for mapped table 'test2' Return Mapper(class_, local_table, *args, **params)įile "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/mapper.py", line 203, in _init_įile "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/mapper.py", line 767, in _configure_pks ![]() When I run 'alembic revision -autogenerate' to create migration script, and got below error:įile "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/_init_.py", line 1129, in mapper You can see that Test2 is a table without a primary key. Fid = Column(Integer, ForeignKey(' test1.id')) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |