I am making a dynamic blog using flask but when i try to connect to the databse i get the error in the title. Here's my code.
from flask import Flask, render_template, request
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:@localhost/gamerhaven'
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=True)
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 contact():
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, phone_num = phone, msg = message, date= datetime.now(),email = email )
db.session.add(entry)
db.session.commit()
return render_template('contact.html')
app.run(debug=True)
And this is the error i get.
<pre>C:\Python\python.exe C:/Users/Swapana/PycharmProjects/flask/main.py
Traceback (most recent call last):
File "C:\Users\admin\PycharmProjects\flask\main.py", line 10, in <module>
class Contacts(db.Model):
File "C:\Users\admin\PycharmProjects\flask\main.py", line 12, in Contacts
name = db.Column(db.String(80), nullable=False)
TypeError: Column() got an unexpected keyword argument 'nullable'
I pretty much only know the basics of python and this error is driving me crazy for the past 2 days as i can't move forward with my project.
Please help.
What I have tried:
I have checked all the code for typos but i didn't find any. I searched for the solution on the internet but i guess no one has encountered a problem like this. I have posted on other similar sites but didn't get any replies.