0

I have checked out Alembic Migrations on Multiple Models but the I way I build my SQLAlchemy models is different.

In src/models/__init__.py:

from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
from .Model1 import Model1
MyMetadata = [Model1.metadata]

In src/models/Model1.py:

from . import db
class Model1(db.Model):

In migrations/env.py:

from src.models import MyMetadata
target_metadata = MyMetadata

When I run alembic revision --autogenerate -m "Initial", I bump into the following error:

ValueError: Duplicate table keys across multiple MetaData objects: "model1", "model2", "model3"

Any advice and insight is appreciated.

Alex Waygood
  • 6,304
  • 3
  • 24
  • 46
Kok How Teh
  • 3,298
  • 6
  • 47
  • 85
  • 2
    You want `MyMetadata = db.Model.metadata`; `db.Model` is equivalent to `Base` in flask-sqlalchemy. – snakecharmerb Sep 27 '21 at 09:47
  • 1
    Does this answer your question? [Alembic Migrations on Multiple Models](https://stackoverflow.com/questions/48053955/alembic-migrations-on-multiple-models) – snakecharmerb Sep 27 '21 at 10:48

0 Answers0