映射器映射器|用户|用户无法为映射表“用户”组合任何主键列

时间:2019-04-02 11:19:43

标签: python flask sqlalchemy flask-sqlalchemy

from sqlalchemy import *
from sqlalchemy import create_engine, ForeignKey
from sqlalchemy import Column, Date, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, backref

engine = create_engine('sqlite:///database.db', echo=True)
Base = declarative_base()

########################################################################
class User(Base):
    """"""
    __tablename__ = "users"

id = Column(Integer, primary_key=True)
username = Column(String)
password = Column(String)

#----------------------------------------------------------------------
def __init__(self, username, password):
    """"""
    self.username = username
    self.password = password

# create tables
Base.metadata.create_all(engine)

这应该以文件名 database.db 创建一个db结构,但是错误弹出,我该如何解决? 任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

这是一个缩进问题。 解决了。 解决方案:

from sqlalchemy import *
from sqlalchemy import create_engine, ForeignKey
from sqlalchemy import Column, Date, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, backref

engine = create_engine('sqlite:///tutorial.db', echo=True)
Base = declarative_base()

########################################################################
class User(Base):
    """"""
    __tablename__ = "users"

    id = Column(Integer, primary_key=True)
    username = Column(String)
    password = Column(String)

#----------------------------------------------------------------------
def __init__(self, username, password):
    """"""
    self.username = username
    self.password = password

# create tables
Base.metadata.create_all(engine)

答案 1 :(得分:0)

就我而言,我收到此错误是因为我这样写

<div [ngStyle]="{'background-color': cardData.color, 'padding': '10px 20px'}">Some Content</div>

VS

Column('id', Integer)
Column('username', String)