sqlalchemy searches my tables twice.
I've been looking for a problem all day, but I can't find it
apps/books/models
print('before')
class Book(Base):
__tablename__ = 'books'
id = Column(Integer, primary_key=True)
title = Column(String, nullable=False,unique=True)
descriptions = Column(String)
file_path = Column(String,unique=True)
users = relationship("User", secondary="book_users", back_populates='books')
book_users = Table('book_users', Base.metadata,
Column('book_id', ForeignKey('books.id'), primary_key=True),
Column('users_id', ForeignKey('users.id'), primary_key=True),
)
print('after')
class Part(Base):
__tablename__ = 'parts'
id = Column(Integer, primary_key=True)
title = Column(String, nullable=False)
descriptions = Column(String)
book_id = Column('book_id',ForeignKey('books.id'))
book = relationship('Book',backref='parts')
apps/users/models
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True, index=True)
username = Column(String, unique=True)
last_name = Column(String)
hashed_password = Column(String)
books = relationship("Book", secondary="book_users", back_populates='users')
apps/database
from decouple import config
USER = config('user')
PASSWORD = config('password')
DB = config('db')
HOST = config('host')
SQLALCHEMY_DATABASE_URL = f"postgresql://{USER}:{PASSWORD}#{HOST}/{DB}"
engine = create_engine(SQLALCHEMY_DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
def get_db():
db = Session(bind=engine)
try:
yield db
finally:
db.close()
im tryed without decouple,it didn't help
apps/main
import sys,os
sys.path.insert(0, os.path.abspath(".."))
sys.path.insert(0, os.path.abspath("..."))
from fastapi import FastAPI
from database import engine, Base
from users.routers import router as router_user
from books.routers import router as router_book
def create_db():
Base.metadata.create_all(bind=engine)
app = FastAPI(title="Shop")
#app.on_event("startup")
def on_startup():
create_db()
app.include_router(router=router_user)
app.include_router(router=router_book)
inserts is only one way for my imports)
exception
before
after
before
Process SpawnProcess-4:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/Users/kana/Desktop/author/env/lib/python3.10/site-packages/uvicorn/subprocess.py", line 76, in subprocess_started
target(sockets=sockets)
File "/Users/kana/Desktop/author/env/lib/python3.10/site-packages/uvicorn/server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "uvloop/loop.pyx", line 1501, in uvloop.loop.Loop.run_until_complete
File "/Users/kana/Desktop/author/env/lib/python3.10/site-packages/uvicorn/server.py", line 67, in serve
config.load()
File "/Users/kana/Desktop/author/env/lib/python3.10/site-packages/uvicorn/config.py", line 458, in load
self.loaded_app = import_from_string(self.app)
File "/Users/kana/Desktop/author/env/lib/python3.10/site-packages/uvicorn/importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/Users/kana/Desktop/author/apps/./main.py", line 9, in <module>
from books.routers import router as router_book
File "/Users/kana/Desktop/author/apps/./books/routers.py", line 13, in <module>
from .models import Book, Part
File "/Users/kana/Desktop/author/apps/./books/models.py", line 9, in <module>
class Book(Base):
File "/Users/kana/Desktop/author/env/lib/python3.10/site-packages/sqlalchemy/orm/decl_api.py", line 72, in __init__
_as_declarative(reg, cls, dict_)
File "/Users/kana/Desktop/author/env/lib/python3.10/site-packages/sqlalchemy/orm/decl_base.py", line 126, in _as_declarative
return _MapperConfig.setup_mapping(registry, cls, dict_, None, {})
File "/Users/kana/Desktop/author/env/lib/python3.10/site-packages/sqlalchemy/orm/decl_base.py", line 177, in setup_mapping
return cfg_cls(registry, cls_, dict_, table, mapper_kw)
File "/Users/kana/Desktop/author/env/lib/python3.10/site-packages/sqlalchemy/orm/decl_base.py", line 322, in __init__
self._setup_table(table)
File "/Users/kana/Desktop/author/env/lib/python3.10/site-packages/sqlalchemy/orm/decl_base.py", line 811, in _setup_table
table_cls(
File "<string>", line 2, in __new__
File "/Users/kana/Desktop/author/env/lib/python3.10/site-packages/sqlalchemy/util/deprecations.py", line 309, in warned
return fn(*args, **kwargs)
File "/Users/kana/Desktop/author/env/lib/python3.10/site-packages/sqlalchemy/sql/schema.py", line 584, in __new__
raise exc.InvalidRequestError(
sqlalchemy.exc.InvalidRequestError: Table 'books' is already defined for this MetaData instance. Specify 'extend_existing=True' to redefine options and columns on an existing Table object.
how you can look, my program broken in apps/books/models after
class Book(Base)
if i switch Book and Part, error will be in Part
any hint will be gratefully accepted
If you encounter this problem, you need to thoroughly change every import in your program, specifying the same path from the root directory everywhere.
another reason for the problem may be the architecture of the project.
my first reason why my database didn't create tables is because it was on the same level as the tables. in my case, it was in apps/utils/main when the tables were at the apps/books/models
level, he added it to Base.metadata.tables, but when he moved to apps/utils/main the Base.metadata.tables list was empty.
when I pulled it to the current level, the problem disappeared
resume:
string Base.metadata.create_all(bind=engine) must be a level higher than module models (or another name your models)
and update your imports
Related
I created two models in my Django db. Now, I want to make migrations, but it shows error like this: AttributeError: module 'django.db.models.signals' has no attribute 'post_syncdb' . I tried to google the answer and found that this signal was deprecated in new Django version. It is not my project and I can't change the current version, so my colleagues recommended me to find the solution. What am I supposed to do if I can't change the version of Django and working on dev branch in project? How do I make migrations? What packages I can update?
My models:
class Categories(models.Model):
name = models.CharField(max_length=100)
position = models.IntegerField(unique=True)
def __str__(self):
return self.name
#classmethod
def get_default_pk(cls):
obj, created = cls.objects.get_or_create(
name='No category was added',
position=99
)
return obj.pk
class Shop(models.Model):
name = models.CharField(_('shop name'), max_length=128)
domain = models.CharField(_('domain'), max_length=128)
active = models.BooleanField(_('active'), default=True)
position = models.PositiveSmallIntegerField(_('position'), default=0)
category = models.ForeignKey(Categories, on_delete=models.CASCADE, related_name='related_name_category',
default=Categories.get_default_pk())
class Meta:
ordering = ('position', 'name')
verbose_name = _('shop')
verbose_name_plural = _('shops')
def __str__(self):
return self.name
The whole traceback after running python3 manage.py makemigrations:
Traceback (most recent call last):
File "/Users/ArtemBoss/GitHubRepos/pricemon/manage.py", line 22, in <module>
main()
File "/Users/ArtemBoss/GitHubRepos/pricemon/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/core/management/__init__.py", line 420, in execute
django.setup()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/apps/registry.py", line 116, in populate
app_config.import_models()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/django/apps/config.py", line 304, in import_models
self.models_module = import_module(models_module_name)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/constance/models.py", line 30, in <module>
signals.post_syncdb.connect(create_perm, dispatch_uid="constance.create_perm")
AttributeError: module 'django.db.models.signals' has no attribute 'post_syncdb'
Make sure that no model in your project uses post_syncdb as if so, it will prevent you from running the migrations command.
Also why can't you use an appropriate version of Django?
I have installed the following packages -
SQLAlchemy==1.4.41
sqlalchemy-spanner==1.2.2
alembic==1.8.1
Then I created a file main.py where I am creating a SQLAlchemy engine for cloud spanner.
from sqlalchemy import create_engine, MetaData
from sqlalchemy.ext.declarative import declarative_base
engine = create_engine(
"spanner+spanner:///projects/spanner-project/instances/spanner-instance/databases/spanner-database"
)
metadata = MetaData()
Base = declarative_base(metadata=metadata)
Then in alembic.ini I have used the same url as shown above for engine.
sqlalchemy.url = spanner+spanner:///projects/spanner-project/instances/spanner-instance/databases/spanner-database
Also in env.py I have set the base's matadata as shown below -
from app.main import Base
target_metadata = Base.metadata
I also have a models.py which has just one model as shown below -
from app.main import Base
from sqlalchemy import (
Column,
Integer,
String,
)
class Users(Base):
__tablename__ = "users"
__table_args__ = {
'extend_existing': True,
}
id = Column(Integer, primary_key=True)
name = Column(String(50))
When I run the alembic command to generate migrations I see an exception of KeyError: 'spanner+spanner'.
CMD -
alembic revision --autogenerate -m "first migrations"
Exception -
Traceback (most recent call last):
File "/usr/local/bin/alembic", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.10/site-packages/alembic/config.py", line 590, in main
CommandLine(prog=prog).main(argv=argv)
File "/usr/local/lib/python3.10/site-packages/alembic/config.py", line 584, in main
self.run_cmd(cfg, options)
File "/usr/local/lib/python3.10/site-packages/alembic/config.py", line 561, in run_cmd
fn(
File "/usr/local/lib/python3.10/site-packages/alembic/command.py", line 229, in revision
script_directory.run_env()
File "/usr/local/lib/python3.10/site-packages/alembic/script/base.py", line 569, in run_env
util.load_python_file(self.dir, "env.py")
File "/usr/local/lib/python3.10/site-packages/alembic/util/pyfiles.py", line 94, in load_python_file
module = load_module_py(module_id, path)
File "/usr/local/lib/python3.10/site-packages/alembic/util/pyfiles.py", line 110, in load_module_py
spec.loader.exec_module(module) # type: ignore
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/code/app/alembic/env.py", line 79, in <module>
run_migrations_online()
File "/code/app/alembic/env.py", line 68, in run_migrations_online
context.configure(
File "<string>", line 8, in configure
File "/usr/local/lib/python3.10/site-packages/alembic/runtime/environment.py", line 822, in configure
self._migration_context = MigrationContext.configure(
File "/usr/local/lib/python3.10/site-packages/alembic/runtime/migration.py", line 268, in configure
return MigrationContext(dialect, connection, opts, environment_context)
File "/usr/local/lib/python3.10/site-packages/alembic/runtime/migration.py", line 196, in __init__
self.impl = ddl.DefaultImpl.get_by_dialect(dialect)(
File "/usr/local/lib/python3.10/site-packages/alembic/ddl/impl.py", line 123, in get_by_dialect
return _impls[dialect.name]
I tried to by changing the URL in alembic.ini from spanner+sapnner:///..... to spanner:///... but then I got this exception -
Traceback (most recent call last):
File "/usr/local/bin/alembic", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.10/site-packages/alembic/config.py", line 590, in main
CommandLine(prog=prog).main(argv=argv)
File "/usr/local/lib/python3.10/site-packages/alembic/config.py", line 584, in main
self.run_cmd(cfg, options)
File "/usr/local/lib/python3.10/site-packages/alembic/config.py", line 561, in run_cmd
fn(
File "/usr/local/lib/python3.10/site-packages/alembic/command.py", line 229, in revision
script_directory.run_env()
File "/usr/local/lib/python3.10/site-packages/alembic/script/base.py", line 569, in run_env
util.load_python_file(self.dir, "env.py")
File "/usr/local/lib/python3.10/site-packages/alembic/util/pyfiles.py", line 94, in load_python_file
module = load_module_py(module_id, path)
File "/usr/local/lib/python3.10/site-packages/alembic/util/pyfiles.py", line 110, in load_module_py
spec.loader.exec_module(module) # type: ignore
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/code/app/alembic/env.py", line 79, in <module>
run_migrations_online()
File "/code/app/alembic/env.py", line 61, in run_migrations_online
connectable = engine_from_config(
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/create.py", line 743, in engine_from_config
return create_engine(url, **options)
File "<string>", line 2, in create_engine
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/deprecations.py", line 309, in warned
return fn(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/create.py", line 522, in create_engine
entrypoint = u._get_entrypoint()
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/url.py", line 655, in _get_entrypoint
cls = registry.load(name)
File "/usr/local/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 343, in load
raise exc.NoSuchModuleError(
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:spanner
Also when I use spanner+spanner:///... to creating and engine and then further use it to create db tables then I am able to do that successfully.
from app.main import engine, Base
from sqlalchemy import (
Column,
Integer,
String,
)
class Users(Base):
__tablename__ = "users"
__table_args__ = {
'extend_existing': True,
}
id = Column(Integer, primary_key=True)
name = Column(String(50))
Base.metadata.create_all(engine)
Just by running this model I am able to create the table.
python models.py
What do I do to use alembic with spanner?
You're using SQLAlchemy 1.4, which means it must be everywhere spanner+spanner. Just spanner will not work. As the problem appears only for Alembic, reinstall will also not help - the problem is in configurations somewhere.
Can you show your env.py file? There must be written something like this:
class SpannerImpl(DefaultImpl):
__dialect__ = "spanner+spanner"
Looking at your traceback, I suspect, in the env.py the dialect is written as just spanner, which causes the error.
I am developing a Student management system in django and while making it I got this
class Dept(models.Model):
id = models.CharField(primary_key='True', max_length=100)
name = models.CharField(max_length=200)
def __str__(self):
return self.name
class Course(models.Model):
dept = models.ForeignKey(Dept, on_delete=models.CASCADE)
id = models.CharField(primary_key='True', max_length=50)
name = models.CharField(max_length=50)
shortname = models.CharField(max_length=50, default='X')
def __str__(self):
return self.name
and while doing make migrations I get this error
by what means Can I get this right and how can I tackle this error
(studentmanagementsystem) C:\Users\harsh\dev\student management\student_management>python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\harsh\anaconda3\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\harsh\anaconda3\lib\site-packages\django\core\management\__init__.py", line 357, in execute
django.setup()
File "C:\Users\harsh\anaconda3\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\harsh\anaconda3\lib\site-packages\django\apps\registry.py", line 112, in populate
app_config.import_models()
File "C:\Users\harsh\anaconda3\lib\site-packages\django\apps\config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\harsh\anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\harsh\dev\student management\student_management\student_app\models.py", line 10, in <module>
class Dept(models.Model):
File "C:\Users\harsh\dev\student management\student_management\student_app\models.py", line 18, in Dept
class Course(models.Model):
File "C:\Users\harsh\dev\student management\student_management\student_app\models.py", line 19, in Course
dept = models.ForeignKey(Dept, on_delete=models.CASCADE)
NameError: name 'Dept' is not defined
(studentmanagementsystem) C:\Users\harsh\dev\student management\student_management>
Honestly, I do not know why you were getting this error as what you have shown here in the example is correct. The only times (at least that I know of) you get this error is when:
The two models are defined in different files and there is a problem with importing the relationship model.
The model that the relationship is being created with is defined after the relationship. In your example, it would mean defining the Dept model after the Course model.
You can import your models as a string using APP_NAME.MODEL_NAME, which avoids such cases, specially the second scenario I have described.
class Course(models.Model):
# Assuming your model resides in an app called 'student_app'
dept = models.ForeignKey('student_app.Dept', on_delete=models.CASCADE)
I was trying to build a model for the profile details of the user of my django web app like:
class UserDetails(models.Model):
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
profilePicture = models.ImageField(blank = True, upload_to='profile_pics/'+self.user.id+'/')
country = models.CharField(max_length = 50, default='India')
gender = models.CharField(max_length=10, default='NA')
birthday = models.DateField(default=datetime.now())
phone = models.CharField(max_length=15)
I have an image field in the above model and I want to upload the incoming images to the path profile_pics/<id of the user whose profile is being set up>/ within my media storage path. I tried to do that by specifying the upload_to attribute of the image field as upload_to = 'profile_pics/'+self.user.id+'/'. I am using AWS S3 for my media storage and I have put the necessary settings in my settings as:
AWS_ACCESS_KEY_ID = 'myaccesskeyid'
AWS_SECRET_ACCESS_KEY = 'mysecretaccesskey'
AWS_STORAGE_BUCKET_NAME = 'mybucketname'
AWS_S3_FILE_OVERWRITE = False
AWS_DEFAULT_ACL = None
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
When I try to make the migrations, I get the following error:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/suraj/Work/treeapp/treeapp-backend/treeEnv/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/suraj/Work/treeapp/treeapp-backend/treeEnv/lib/python3.6/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/home/suraj/Work/treeapp/treeapp-backend/treeEnv/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/suraj/Work/treeapp/treeapp-backend/treeEnv/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/suraj/Work/treeapp/treeapp-backend/treeEnv/lib/python3.6/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/home/suraj/Work/treeapp/treeapp-backend/treeEnv/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/suraj/Work/treeapp/treeapp-backend/userMgmt/models.py", line 7, in <module>
class UserDetails(models.Model):
File "/home/suraj/Work/treeapp/treeapp-backend/userMgmt/models.py", line 9, in UserDetails
profilePicture = models.ImageField(blank = True, upload_to='profile_pics/'+self.user.id+'/')
NameError: name 'self' is not defined
Please help me out to set the default path of the image uploads to this model to profile_pics/<id of the user whose profile is being set up>/.
You can pass a callable to the upload_to=… parameter [Django-doc]:
class UserDetails(models.Model):
def profile_picture_upload(self, filename):
return 'profile_pics/{}/{}'.format(self.user_id, filename)
# …
profilePicture = models.ImageField(blank=True, upload_to=profile_picture_upload)
Note: normally the name of the fields in a Django model are written in snake_case, not PerlCase, so it should be: profile_picture instead of profilePicture.
The Model is below plus error message below that.
I am trying to create some array columns using Alembic but getting NameError: name 'String' is not defined.
Any help valued.
thanks!
from sqlalchemy import Column, String, Integer, DateTime
from serve_spec.db_global import db
import datetime
from time import time
from sqlalchemy.dialects.postgresql import JSON
from sqlalchemy.dialects.postgresql import ARRAY
class Issues(db.Base):
__tablename__ = 'issues'
id = Column(String, primary_key=True)
thread_id = Column(String, nullable=False)
created = Column(DateTime(timezone=False), nullable=False, default=datetime.datetime.utcnow)
created_timestamp = Column(Integer, nullable=False, default=time)
created_by_user_name = Column(String, nullable=False)
is_parent = Column(Integer, nullable=False)
parent_title = Column(String)
subscribed = Column(ARRAY(String))
unsubscribed = Column(ARRAY(String))
pending_notifications_web = Column(ARRAY(String))
pending_notifications_email = Column(ARRAY(String))
markdown_text = Column(String, nullable=False, )
kernel_id = Column(String, nullable=False)
state = Column(String, nullable=False, default='open')
labels = Column(JSON())
Here is the output, with the error at the bottom:
(venv3.4.2) ubuntu#ip-172-31-8-128:/var/www/www.example.org/src/crowdwave$ PYTHONPATH=. alembic upgrade head
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
INFO [alembic.runtime.migration] Running upgrade d9bc97e175aa -> dd9e391f807f, Issues is behind
Traceback (most recent call last):
File "/var/www/www.example.org/venv3.4.2/bin/alembic", line 9, in <module>
load_entry_point('alembic==0.8.5', 'console_scripts', 'alembic')()
File "/var/www/www.example.org/venv3.4.2/lib/python3.4/site-packages/alembic/config.py", line 479, in main
CommandLine(prog=prog).main(argv=argv)
File "/var/www/www.example.org/venv3.4.2/lib/python3.4/site-packages/alembic/config.py", line 473, in main
self.run_cmd(cfg, options)
File "/var/www/www.example.org/venv3.4.2/lib/python3.4/site-packages/alembic/config.py", line 456, in run_cmd
**dict((k, getattr(options, k)) for k in kwarg)
File "/var/www/www.example.org/venv3.4.2/lib/python3.4/site-packages/alembic/command.py", line 174, in upgrade
script.run_env()
File "/var/www/www.example.org/venv3.4.2/lib/python3.4/site-packages/alembic/script/base.py", line 397, in run_env
util.load_python_file(self.dir, 'env.py')
File "/var/www/www.example.org/venv3.4.2/lib/python3.4/site-packages/alembic/util/pyfiles.py", line 81, in load_python_file
module = load_module_py(module_id, path)
File "/var/www/www.example.org/venv3.4.2/lib/python3.4/site-packages/alembic/util/compat.py", line 68, in load_module_py
module_id, path).load_module(module_id)
File "<frozen importlib._bootstrap>", line 539, in _check_name_wrapper
File "<frozen importlib._bootstrap>", line 1614, in load_module
File "<frozen importlib._bootstrap>", line 596, in _load_module_shim
File "<frozen importlib._bootstrap>", line 1220, in load
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "alembic/env.py", line 82, in <module>
run_migrations_online()
File "alembic/env.py", line 77, in run_migrations_online
context.run_migrations()
File "<string>", line 8, in run_migrations
File "/var/www/www.example.org/venv3.4.2/lib/python3.4/site-packages/alembic/runtime/environment.py", line 797, in run_migrations
self.get_context().run_migrations(**kw)
File "/var/www/www.example.org/venv3.4.2/lib/python3.4/site-packages/alembic/runtime/migration.py", line 312, in run_migrations
step.migration_fn(**kw)
File "/var/www/www.example.org/src/crowdwave/alembic/versions/dd9e391f807f_issues_is_behind.py", line 21, in upgrade
op.add_column('issues', sa.Column('pending_notifications_email', postgresql.ARRAY(String()), nullable=True))
NameError: name 'String' is not defined
(venv3.4.2) ubuntu#ip-172-31-8-128:/var/www/www.example.org/src/crowdwave$
Apparently this is an Alembic bug: see https://bitbucket.org/zzzeek/alembic/issues/368/autogenerate-does-not-properly-transform
The fix is to edit the migration file changing
postgresql.ARRAY(String(), nullable=True))
to
postgresql.ARRAY(sa.String(), nullable=True))