我尝试在mysql中创建表并将数据插入其中,而create table成功且无法插入数据,是否有人知道如何修复它,非常感谢...
db = SQLAlchemy(app)
class Article(db.Model):
__tablename__ = 'ar'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
title = db.Column(db.String(100), nullable=False)
content = db.Column(db.Text, nullable=False)
db.create_all()
@app.route('/')
def hello_world():
article1 = Article(title='aaa',content='bbb')
db.session.add(article1)
db.session.commit()
实际创建了表,但数据仍未插入..
mysql> desc ar;
+---------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| title | varchar(100) | NO | | NULL | |
| content | text | NO | | NULL | |
+---------+--------------+------+-----+---------+----------------+
3 rows in set (0.01 sec)
mysql> select * from ar;
Empty set (0.00 sec)
答案 0 :(得分:0)
您需要在浏览器中导航到应用程序路径才能运行代码。同样在应用程序路径中,返回一个值。
我希望你为了说明而错过了回复声明。
我希望这会有所帮助。