trying to follow this tutorial from freecodecamp intro to flask video: https://www.youtube.com/watch?v=Z1RJmh_OqeA
The relevant bit of the video starts at around minute 19
This is my code:
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
app = Flask(name)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///sqlite.db'
# initialize the database with the settings from app
db = SQLAlchemy(app)
class Budget_Item(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50), nullable=False)
cost = db.Column(db.Float, nullable=False)
date_created = db.Column(db.DateTime, default=datetime.utcnow)
recurring = db.Column(db.Boolean, nullable=False)
due_date = db.Column(db.DateTime, nullable=True)
def __repr__(self):
return '<Budget_Item %r>' % self.id
@app.route('/')
def index():
return render_template('index.html')
if name == "main":
app.run(debug=True)
when in the terminal I run from app import db I don't have a problem, but then when I run db.create_all() I get AttributeError: can't set attribute. I've tried changing the class name to BudgetName in case the problem was the underscore, and I've tried completely recreating the code written in the video, and I get the same error.
Error traceback:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/mcamp/.local/share/virtualenvs/Python-docker-built-challenge-VYztjUFt/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py", line 1039, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
File "/home/mcamp/.local/share/virtualenvs/Python-docker-built-challenge-VYztjUFt/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py", line 1031, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), **extra)
File "/home/mcamp/.local/share/virtualenvs/Python-docker-built-challenge-VYztjUFt/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py", line 962, in get_engine
return connector.get_engine()
File "/home/mcamp/.local/share/virtualenvs/Python-docker-built-challenge-VYztjUFt/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py", line 555, in get_engine
options = self.get_options(sa_url, echo)
File "/home/mcamp/.local/share/virtualenvs/Python-docker-built-challenge-VYztjUFt/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py", line 570, in get_options
self._sa.apply_driver_hacks(self._app, sa_url, options)
File "/home/mcamp/.local/share/virtualenvs/Python-docker-built-challenge-VYztjUFt/lib/python3.9/site-packages/flask_sqlalchemy/__init__.py", line 914, in apply_driver_hacks
sa_url.database = os.path.join(app.root_path, sa_url.database)
AttributeError: can't set attribute