Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让红移方言与SQLAlchemy和Alembic一起在Python中工作以进行迁移?_Python_Sqlalchemy_Amazon Redshift_Alembic - Fatal编程技术网

如何让红移方言与SQLAlchemy和Alembic一起在Python中工作以进行迁移?

如何让红移方言与SQLAlchemy和Alembic一起在Python中工作以进行迁移?,python,sqlalchemy,amazon-redshift,alembic,Python,Sqlalchemy,Amazon Redshift,Alembic,当我尝试“alembic upgrade+1”时,会出现以下错误,这是为了进行数据库迁移 File "/home/jason/redshift/env/lib/python3.4/site-packages/sqlalchemy/engine/default.py", line 436, in do_execute cursor.execute(statement, parameters) psycopg2.NotSupportedError: Column "analyses.id"

当我尝试“alembic upgrade+1”时,会出现以下错误,这是为了进行数据库迁移

File "/home/jason/redshift/env/lib/python3.4/site-packages/sqlalchemy/engine/default.py", line 436, in do_execute
    cursor.execute(statement, parameters)
psycopg2.NotSupportedError: Column "analyses.id" has unsupported type "serial".
my SQLAlchemy models.py包含:

from alembic.ddl.postgresql import PostgresqlImpl
class RedshiftImpl(PostgresqlImpl):
    __dialect__ = 'redshift'
我的url/主机是:

sqlalchemy.url = redshift://USER:PASSWORD@XXXX.XXXXXXX.us-east-1.redshift.amazonaws.com:5439/

但出于某种原因,它似乎没有使用这种方言。是否需要修改env.py?或者是models.py?

我也有同样的问题;这是0.4.1中的一个bug,这是本文发表时PyPI上可用的最新版本。我直接从Github安装了它,它工作正常(在撰写本文时master是在0.5.1a上)。

问题在于主键的处理。如果在pip上安装并生成迁移,问题在于PrimarykeyConstraint()方法中,该方法希望创建一个串行列,该列仅存在于postgres中,而不存在于红移中

from alembic import op
import sqlalchemy as sa
from redshift_sqlalchemy import dialect as postgresql

def upgrade():
    op.create_table('mytable',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.PrimaryKeyConstraint('id') # problem is here: wants to create a serial type
    )

还考虑更改迁移,以从ReHeffttSqLalC化工模块导入方言,而不是SqLalCyMy核心。虽然在本例中这并不重要,有些情况下,redshift和postgres方言没有100%对齐。

如何从redshift\u alchemy导入方言?要从github安装,命令是
pip install git+https://github.com/binarydud/redshift_sqlalchemy
Heads up-您的红移密码显示在该url中。