sqlite - 为什么我的 Flask SQLite 表没有占用我添加的新列?
问题描述
我对 Flask 相当陌生,并且正在尝试向我的一个表(称为公司)添加新行,在我尝试将一组新数据提交到所述表之前,一切似乎都运行良好。它一直显示为null,我不知道为什么。我已经对不同的表和列执行了相同的步骤,并且效果很好。任何帮助,将不胜感激。
以下是我的逻辑:
@app.route('/addcompany')
@login_required
def addCompany():
if request.method == 'POST':
company_name = request.form['companyname']
company_description = request.form['companydescription']
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
filename = '1200px-No-logo.svg.png'
if file and EXTENSIONS:
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
logo = 'logos/'+filename
company_website = 'www.google.com' #request.form['companywebsite']
new_company = companies(description=company_description, company_name=company_name, logo=logo, company_website=company_website)
try:
db.session.add(new_company)
db.session.commit()
return redirect('/')
except:
return 'there was an issue adding the company'
else:
return render_template('addcompany.html')
这是数据库。班级:
class companies(db.Model):
id = db.Column(db.Integer, primary_key=True)
description = db.Column(db.String(200), nullable=False)
company_name = db.Column(db.String(50), nullable=False)
logo = db.Column(db.String(200), nullable=True)
company_website = db.Column(db.String(50), nullable=True)
date_created = db.Column(db.DateTime, default=datetime.utcnow())
def __ref__(self):
return '<Company %r>' % self.id
除了 company_website 列之外的所有内容都有效,有什么想法吗?
解决方案
推荐阅读
- power-automate - Power Automate 无法连接到本地数据网关
- c# - 使用 Aforge 对屏幕截图进行操作
- javascript - 如何从 Meteor FS 集合中检索 Jade 中的图像
- javascript - 显示列表中的 1 个特定图像?
- javascript - 在 Vuex 的一个动作中管理两个状态
- python - 是否可以在 Python 2.7 中使用 tkinter(小写)?
- boost-log - boost log:使用formatting_ostream存储日志
- javascript - 我无法在实时 Firebase 网络应用程序中进行分页
- php - 将多维数组展平到特定索引
- batch-file - For 循环 - 注意文件列表中目录的变化