Я пытаюсь запустить миграцию, чтобы добавить ограничение внешнего ключа. Это когда я пытаюсь добавить artist_id
к моей RSVP
модели в отношениях много-к-одному. У каждого RSVP
может быть только исполнитель, а у исполнителя может быть много rsvps
.
Вот мой код миграции
def upgrade():
with op.batch_alter_table('rsvp') as batch_op:
batch_op.create_foreign_key(
"fk_artist_rsvp", "rsvp",
"artist", ["artist_id"], ["id"])
def downgrade():
with op.batch_alter_table('rsvp') as batch_op:
batch_op.drop_constraint(
u'fk_artist_rsvp', 'artist', type_='foreignkey')
При запуске я получаю следующую ошибку
Traceback (most recent call last):
File "/Users/dariusmandres/.pyenv/versions/st-art/bin/alembic", line 11, in <module>
load_entry_point('alembic==1.4.0', 'console_scripts', 'alembic')()
File "/Users/dariusmandres/.pyenv/versions/3.7.0/envs/st-art/lib/python3.7/site-packages/alembic/config.py", line 577, in main
CommandLine(prog=prog).main(argv=argv)
File "/Users/dariusmandres/.pyenv/versions/3.7.0/envs/st-art/lib/python3.7/site-packages/alembic/config.py", line 571, in main
self.run_cmd(cfg, options)
File "/Users/dariusmandres/.pyenv/versions/3.7.0/envs/st-art/lib/python3.7/site-packages/alembic/config.py", line 551, in run_cmd
**dict((k, getattr(options, k, None)) for k in kwarg)
File "/Users/dariusmandres/.pyenv/versions/3.7.0/envs/st-art/lib/python3.7/site-packages/alembic/command.py", line 298, in upgrade
script.run_env()
File "/Users/dariusmandres/.pyenv/versions/3.7.0/envs/st-art/lib/python3.7/site-packages/alembic/script/base.py", line 489, in run_env
util.load_python_file(self.dir, "env.py")
File "/Users/dariusmandres/.pyenv/versions/3.7.0/envs/st-art/lib/python3.7/site-packages/alembic/util/pyfiles.py", line 98, in load_python_file
module = load_module_py(module_id, path)
File "/Users/dariusmandres/.pyenv/versions/3.7.0/envs/st-art/lib/python3.7/site-packages/alembic/util/compat.py", line 173, in load_module_py
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "alembic/env.py", line 77, in <module>
run_migrations_online()
File "alembic/env.py", line 71, in run_migrations_online
context.run_migrations()
File "<string>", line 8, in run_migrations
File "/Users/dariusmandres/.pyenv/versions/3.7.0/envs/st-art/lib/python3.7/site-packages/alembic/runtime/environment.py", line 846, in run_migrations
self.get_context().run_migrations(**kw)
File "/Users/dariusmandres/.pyenv/versions/3.7.0/envs/st-art/lib/python3.7/site-packages/alembic/runtime/migration.py", line 518, in run_migrations
step.migration_fn(**kw)
File "/Users/dariusmandres/projects/st-art/alembic/versions/1d80258c8056_artist_rsvp.py", line 23, in upgrade
"artist", ["artist_id"], ["id"])
File "<string>", line 3, in create_foreign_key
File "/Users/dariusmandres/.pyenv/versions/3.7.0/envs/st-art/lib/python3.7/site-packages/alembic/operations/ops.py", line 702, in batch_create_foreign_key
return operations.invoke(op)
File "/Users/dariusmandres/.pyenv/versions/3.7.0/envs/st-art/lib/python3.7/site-packages/alembic/operations/base.py", line 374, in invoke
return fn(self, operation)
File "/Users/dariusmandres/.pyenv/versions/3.7.0/envs/st-art/lib/python3.7/site-packages/alembic/operations/toimpl.py", line 151, in create_constraint
operation.to_constraint(operations.migration_context)
File "/Users/dariusmandres/.pyenv/versions/3.7.0/envs/st-art/lib/python3.7/site-packages/alembic/operations/ops.py", line 547, in to_constraint
**self.kw
File "/Users/dariusmandres/.pyenv/versions/3.7.0/envs/st-art/lib/python3.7/site-packages/alembic/operations/schemaobj.py", line 46, in foreign_key_constraint
schema=referent_schema
File "<string>", line 2, in __new__
File "/Users/dariusmandres/.pyenv/versions/3.7.0/envs/st-art/lib/python3.7/site-packages/sqlalchemy/util/deprecations.py", line 130, in warned
return fn(*args, **kwargs)
File "/Users/dariusmandres/.pyenv/versions/3.7.0/envs/st-art/lib/python3.7/site-packages/sqlalchemy/sql/schema.py", line 470, in __new__
key = _get_table_key(name, schema)
File "/Users/dariusmandres/.pyenv/versions/3.7.0/envs/st-art/lib/python3.7/site-packages/sqlalchemy/sql/schema.py", line 77, in _get_table_key
return schema + "." + name
TypeError: can only concatenate list (not "str") to list
Что происходит?