sqlalchemy编译错误:无法为NullType()生成DDL

时间:2019-05-16 11:02:46

标签: python sqlalchemy pycharm flask-sqlalchemy

错误:

sqlalchemy.exc.CompileError: (in table 'person', column 'id'): Can't generate DDL for NullType(); did you forget to specify a type on this Column?

我使用SQLite,但无法创建表

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app=Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI']='sqlite:///one.db'
db=SQLAlchemy(app)
class Person(db.Model):
    id = db.Column(db.Integer,primary_key=True)
    name = db.Column(db.String(20))
    pets = db.relationship('Pet',backref='owner')

class Pet(db.Model):
    id = db.Column(db.Integer,primary_key=True)
    name = db.Column(db.String(20))
    owner_id = db.Column(db.Integer,db.ForeignKey('person.id'))

0 个答案:

没有答案