I am writing the databases code to let the user enter City Name, City Rank in the box just like Username and Password.

But I’m getting this message when I run the code.

sqlalchemy.exc.OperationalError

“sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: cities [SQL: SELECT cities.id AS cities_id, cities.city_name AS cities_city_name, cities.city_rank AS cities_city_rank FROM cities]”

__init__.py

import flask

import os

from flask_sqlalchemy import SQLAlchemy

basedir = os.path.abspath(os.path.dirname(__file__))

#instance of the flask class

app_obj = flask.Flask(__name__)

app_obj.config.from_mapping(

SECRET_KEY = ‘it-dont-matter’,

SQLALCHEMY_DATABASE_URI = ‘sqlite:///’ + os.path.join(basedir, ‘app.db’),

SQLALCHEMY_TRACK_MODIFICATIONS = False

)

db = SQLAlchemy(app_obj)

from app import routes, models

forms.py

from flask_wtf import FlaskForm

from wtforms import StringField, IntegerField, BooleanField, SubmitField

from wtforms.validators import DataRequired

class Cities(FlaskForm):

city_name = StringField(‘City Name’,validators=[DataRequired()])

city_rank = IntegerField(‘City Rank’,validators=[DataRequired()])

is_visited = BooleanField(‘Visited’)

submit = SubmitField(‘Submit’)

models.py

from app import db

from datetime import datetime

class Cities(db.Model):

#create column for database

#primary_key means it is unique

id = db.Column(db.Integer, primary_key=True)

city_name= db.Column(db.String(64), unique=True, index=True)

city_rank = db.Column(db.Integer())

posts = db.relationship(‘Post’, backref=’author’, lazy=’dynamic’)

def __repr__(self):

return f'{self.city_name} with rank {self.city_rank}’

class Post(db.Model):

#create column for database

#primary_key means it is unique

id = db.Column(db.Integer, primary_key=True)

body = db.Column(db.String(256))

timestamp = db.Column(db.DateTime, default=datetime.utcnow)

user_id = db.Column(db.Integer, db.ForeignKey(‘cities.id’))

def __repr__(self):

return f'<Post> {self.id}: {self.body}>’

routes.py

from app import app_obj

from app.forms import Cities

from flask import render_template, flash, redirect, request

from app import db

from app.models import Cities, Post

@app_obj.route(“/login”, methods = [‘GET’,’POST’])

def login():

name = ‘Khuong’

title = ‘Top Cities’

top_cities = Cities.query.all()

form = Cities()

if request.method == ‘POST’:

if not request.form [‘city_name’] or not request.form [‘city_rank’]:

flask(‘Invalid city_name or city_rank’)

else:

top_cities = Cities(city_name = form.city_name.data, city_rank = form.city_rank.data)

db.sesion.add(top_cities)

db.session.commit()

flask(‘New city is added!’)

return redirect(‘/’)

return render_template(“home.html”, name=name, title=title, form=form)

run.py

#from library import app

from app import app_obj

app_obj.run(debug=True)

base.html

<!DOCTYPE html>

<html>

<head>

{% if title %}

<title>{{title}}!</title>

{% else %}

<title>Home</title>

{% endif %}

</head>

<body>

{% with messages = get_flashed_messages() %}

{% if messages %}

<ul>

{% for m in message %}

<li>{{ m }}</li>

{% endfor %}

</ul>

{% endif %}

{% endwith %}

{% block content %}

{% endblock %}

</body>

</html>

home.html

<!DOCTYPE html>

<html>

<head>

{% if title %}

<title>{{title}}!</title>

{% else %}

<title>Home</title>

{% endif %}

</head>

<body>

{% with messages = get_flashed_messages() %}

{% if messages %}

<ul>

{% for m in message %}

<li>{{ m }}</li>

{% endfor %}

</ul>

{% endif %}

{% endwith %}

{% block content %}

{% endblock %}

</body>

</html>

I am writing the databases code to let the user enter City Name, City Rank in the box just like Username and Password.

But I’m getting this message when I run the code.

sqlalchemy.exc.OperationalError

“sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: cities [SQL: SELECT cities.id AS cities_id, cities.city_name AS cities_city_name, cities.city_rank AS cities_city_rank FROM cities]”

__init__.py

import flask

import os

from flask_sqlalchemy import SQLAlchemy

basedir = os.path.abspath(os.path.dirname(__file__))

#instance of the flask class

app_obj = flask.Flask(__name__)

app_obj.config.from_mapping(

SECRET_KEY = ‘it-dont-matter’,

SQLALCHEMY_DATABASE_URI = ‘sqlite:///’ + os.path.join(basedir, ‘app.db’),

SQLALCHEMY_TRACK_MODIFICATIONS = False

)

db = SQLAlchemy(app_obj)

from app import routes, models

forms.py

from flask_wtf import FlaskForm

from wtforms import StringField, IntegerField, BooleanField, SubmitField

from wtforms.validators import DataRequired

class Cities(FlaskForm):

city_name = StringField(‘City Name’,validators=[DataRequired()])

city_rank = IntegerField(‘City Rank’,validators=[DataRequired()])

is_visited = BooleanField(‘Visited’)

submit = SubmitField(‘Submit’)

models.py

from app import db

from datetime import datetime

class Cities(db.Model):

#create column for database

#primary_key means it is unique

id = db.Column(db.Integer, primary_key=True)

city_name= db.Column(db.String(64), unique=True, index=True)

city_rank = db.Column(db.Integer())

posts = db.relationship(‘Post’, backref=’author’, lazy=’dynamic’)

def __repr__(self):

return f'{self.city_name} with rank {self.city_rank}’

class Post(db.Model):

#create column for database

#primary_key means it is unique

id = db.Column(db.Integer, primary_key=True)

body = db.Column(db.String(256))

timestamp = db.Column(db.DateTime, default=datetime.utcnow)

user_id = db.Column(db.Integer, db.ForeignKey(‘cities.id’))

def __repr__(self):

return f'<Post> {self.id}: {self.body}>’

routes.py

from app import app_obj

from app.forms import Cities

from flask import render_template, flash, redirect, request

from app import db

from app.models import Cities, Post

@app_obj.route(“/login”, methods = [‘GET’,’POST’])

def login():

name = ‘Khuong’

title = ‘Top Cities’

top_cities = Cities.query.all()

form = Cities()

if request.method == ‘POST’:

if not request.form [‘city_name’] or not request.form [‘city_rank’]:

flask(‘Invalid city_name or city_rank’)

else:

top_cities = Cities(city_name = form.city_name.data, city_rank = form.city_rank.data)

db.sesion.add(top_cities)

db.session.commit()

flask(‘New city is added!’)

return redirect(‘/’)

return render_template(“home.html”, name=name, title=title, form=form)

run.py

#from library import app

from app import app_obj

app_obj.run(debug=True)

base.html

<!DOCTYPE html>

<html>

<head>

{% if title %}

<title>{{title}}!</title>

{% else %}

<title>Home</title>

{% endif %}

</head>

<body>

{% with messages = get_flashed_messages() %}

{% if messages %}

<ul>

{% for m in message %}

<li>{{ m }}</li>

{% endfor %}

</ul>

{% endif %}

{% endwith %}

{% block content %}

{% endblock %}

</body>

</html>

home.html

<!DOCTYPE html>

<html>

<head>

{% if title %}

<title>{{title}}!</title>

{% else %}

<title>Home</title>

{% endif %}

</head>

<body>

{% with messages = get_flashed_messages() %}

{% if messages %}

<ul>

{% for m in message %}

<li>{{ m }}</li>

{% endfor %}

</ul>

{% endif %}

{% endwith %}

{% block content %}

{% endblock %}

</body>

</html>

Calculate your order
Pages (275 words)
Standard price: $0.00
Client Reviews
4.9
Sitejabber
4.6
Trustpilot
4.8
Our Guarantees
100% Confidentiality
Information about customers is confidential and never disclosed to third parties.
Original Writing
We complete all papers from scratch. You can get a plagiarism report.
Timely Delivery
No missed deadlines – 97% of assignments are completed in time.
Money Back
If you're confident that a writer didn't follow your order details, ask for a refund.

Calculate the price of your order

You will get a personal manager and a discount.
We'll send you the first draft for approval by at
Total price:
$0.00
Power up Your Academic Success with the
Team of Professionals. We’ve Got Your Back.
Power up Your Study Success with Experts We’ve Got Your Back.