当我尝试向SQLAlchemy添加新模型时,我收到错误(我在下面使用MySQL)
raise errorclass, errorvalue
sqlalchemy.exc.OperationalError 1005 Can't create table
我从一开始就有模型/表PlayerModel / player我正在尝试添加新表(Base有id列id)
class Base(object):
def __tablename__(self):
return self.__name__.lower()
id = Column(Integer, primary_key=True, nullable=False)
class PlayerModel(Base):
__tablename__ = 'players'
alliances_id = Column(Integer, ForeignKey('alliances.id'), nullable=True)
alliance = relationship('AllianceModel')
username = Column(String(90), nullable=True, default=None)
email = Column(String(75), nullable=True, default=None)
password = Column(String(128), nullable=True, default=None)
money = Column(Integer, nullable=False, default=INITIAL_MONEY)
# used for push notifications
push_token = Column(String(64), nullable=True)
registered_for_push = Column(Boolean, nullable=False, default=False)
device_id = Column(String(64), nullable=True)
device_type = Column(String(64), nullable=True)
device_os = Column(Integer, nullable=True)
notify = Column(Boolean, default=True)
def __repr__(self):
return "<Player('%s')>" % (self.type)
这里抛出错误
class ArmyModel(Base):
__tablename__ = 'army'
player_id = Column(Integer, ForeignKey('players.id', ondelete='CASCADE'), nullable=False, index=True)
speed = Column(Float, nullable=False, default=1)
# mode of army behavior ( always fight, ignore )
mode = Column(Integer, nullable=False)
x = Column(Float, nullable=False, default=0)
y = Column(Float, nullable=False, default=0)
z = Column(Float, nullable=False, default=0)
def __repr__(self):
return "<Army('%s')>" % (self.type)