0
我試圖插入一些數據作爲部署的一部分。我創建了以下修訂蒸餾器腳本AttributeError的Flask&SqlAlchemy - alembic session.add_all()導致AttributeError:'bool'對象沒有屬性'明確'錯誤
revision = '59891ffc8502'
down_revision = '349540cf9cef'
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relationship
Session = sessionmaker()
Base = declarative_base()
class Colours(Base):
__tablename__ = 'colours'
id = sa.Column(sa.Integer, primary_key=True)
name = sa.Column('name', sa.Unicode(length=25), nullable=False)
code = sa.Column('code', sa.Unicode(length=2), nullable=False)
def upgrade():
bind = op.get_bind()
session = Session(bind=bind)
session._model_changes = False
op.alter_column('colours', 'code', new_column_name='code', existing_type=mysql.VARCHAR(length=25))
col = [
{ "name": "Black", "code": "ff00cc" },
{ "name": "Blue", "code": "ff00cc" },
{ "name": "Brown", "code": "ff00cc" },
{ "name": "Gold", "code": "ff00cc" },
{ "name": "Green", "code": "ff00cc" }
]
# populate colours table
colours = { c['name']: Colours(name=unicode(c['name']), code=c['code']) for c in col}
session.add_all(colours.values())
session.commit()
# ### end Alembic commands ###
和升級頭的結果:「布爾」對象有沒有屬性「清晰」的錯誤。 任何線索?
你有過嗎? –