I';我正在尝试使用Python、Flask和php创建网页。。。问题在于它显示了以下错误:参数';主键';未填充错误
这是我的代码,我正试图用数据库创建一个网页,但现在它显示错误和问题。我怎样才能修好它们? 这是main.py文件的代码:I';我正在尝试使用Python、Flask和php创建网页。。。问题在于它显示了以下错误:参数';主键';未填充错误,python,database,flask,flask-sqlalchemy,Python,Database,Flask,Flask Sqlalchemy,这是我的代码,我正试图用数据库创建一个网页,但现在它显示错误和问题。我怎样才能修好它们? 这是main.py文件的代码: from flask import Flask, render_template, request from flask_sqlalchemy import SQLAlchemy app = Flask(__name__, template_folder='template') app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql:/
from flask import Flask, render_template, request
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__, template_folder='template')
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:@localhost/codingthunder'
db = SQLAlchemy(app)
class Contacts(db.Model):
sno = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), nullable=False)
phone_num = db.Column(db.String(12), nullable=False)
msg = db.Column(db.String(120), nullable=False)
date = db.Column(db.String(12), nullable=False)
email = db.Column(db.String(20), Nullable=False)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/contact', methods=['GET', 'POST'])
def contacts():
if request.method == 'POST':
'''Add entry to the database'''
name = request.form.get('name')
email = request.form.get('email')
phone = request.form.get('phone')
message = request.form.get('message')
entry = Contacts(name=name, phome_num=phone, msg=message, email=email)
db.session.add(entry)
db.session.cummit()
return render_template('contact.html')
app.run(debug=True)
错误和问题:
尝试将电子邮件列从可空更改为可空
email=db.Column(db.String(20),nullable=False)