Я получаю эти ошибки, когда пытаюсь запустить свое приложение, полагая, что оно как-то связано с тем, как я импортировал sqlalchemy, но не смог вставить в него пин-код. Я следую этому уроку: https://www.youtube.com/watch?v=cYWiDiIUxQc&list=PL-osiE80TeTs4UjLw5MM6OjgkjFeUxCYH&index=4
это ошибки, которые он мне дает введите описание изображения здесь
все они являются чем-то похожим на экземпляр sqlalchemy, не имеет члена столбца
вот мой код:
from datetime import datetime
from flask import Flask, render_template, url_for, flash, redirect
from flask_sqlalchemy import SQLAlchemy
from forms import RegistrationForm, LoginForm
app = Flask(__name__)
app.config['SECRET_KEY'] = 'thesecretkey'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
db=SQLAlchemy(app)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), unique=True, Nullable=False)
email = db.Column(db.String(120), unique=True, Nullable=False)
image_file = db.Column(db.String(20), Nullable=False, default='default.jpg')
password = db.Column(db.String(60), Nullable=False)
posts = db.relationships('Post', backref='author', lazy=True)
def __repr__(self):
return f"User('{self.username}', '{self.email}', '{self.image_file}',)"
class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), nullable=False)
date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
content = db.Column(db.text, nullable=False)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
def __repr__(self):
return f"User('{self.title}', '{self.date_posted}')"
posts = [
{
'author': 'John Doe',
'title': 'post 1',
'content': 'first post content',
'date': 'March 26, 2020'
},
{
'author': 'Other Person',
'title': 'post 2',
'content': 'second post content' ,
'date': 'March 26, 2020'
}
]
@app.route('/')
@app.route('/home')
def home():
return render_template('home.html', posts=posts)
@app.route('/about')
def about():
return render_template('about.html')
@app.route("/register", methods=['GET', 'POST'])
def register():
form = RegistrationForm()
if form.validate_on_submit():
flash(f'Account created for {form.username.data}!', 'success')
return redirect(url_for('home'))
return render_template('register.html', title='Register', form=form)
@app.route('/login')
def login():
form = LoginForm()
return render_template('login.html', title = 'Login', form=form)
if __name__ == '__main__':
app.run(debug=True)
вот ошибка, которая выдается мне при попытке запустить:
FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning.
warnings.warn(FSADeprecationWarning(
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 192, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/henrym/desktop/hello_flask/env/lib/python3.8/site-packages/flask/__main__.py", line 15, in <module>
main(as_module=True)
File "/Users/henrym/Desktop/hello_flask/env/lib/python3.8/site-packages/flask/cli.py", line 966, in main
cli.main(prog_name="python -m flask" if as_module else None)
File "/Users/henrym/Desktop/hello_flask/env/lib/python3.8/site-packages/flask/cli.py", line 586, in main
return super(FlaskGroup, self).main(*args, **kwargs)
File "/Users/henrym/Desktop/hello_flask/env/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Users/henrym/Desktop/hello_flask/env/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/henrym/Desktop/hello_flask/env/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/henrym/Desktop/hello_flask/env/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/henrym/Desktop/hello_flask/env/lib/python3.8/site-packages/click/decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/Users/henrym/Desktop/hello_flask/env/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/henrym/Desktop/hello_flask/env/lib/python3.8/site-packages/flask/cli.py", line 848, in run_command
app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
File "/Users/henrym/Desktop/hello_flask/env/lib/python3.8/site-packages/flask/cli.py", line 305, in __init__
self._load_unlocked()
File "/Users/henrym/Desktop/hello_flask/env/lib/python3.8/site-packages/flask/cli.py", line 330, in _load_unlocked
self._app = rv = self.loader()
File "/Users/henrym/Desktop/hello_flask/env/lib/python3.8/site-packages/flask/cli.py", line 392, in load_app
app = locate_app(self, import_name, None, raise_if_not_found=False)
File "/Users/henrym/Desktop/hello_flask/env/lib/python3.8/site-packages/flask/cli.py", line 240, in locate_app
__import__(module_name)
File "/Users/henrym/Desktop/hello_flask/app.py", line 12, in <module>
class User(db.Model):
File "/Users/henrym/Desktop/hello_flask/app.py", line 14, in User
username = db.Column(db.String(20), unique=True, Nullable=False)
File "/Users/henrym/Desktop/hello_flask/env/lib/python3.8/site-packages/sqlalchemy/sql/schema.py", line 1396, in __init__
self._extra_kwargs(**kwargs)
File "/Users/henrym/Desktop/hello_flask/env/lib/python3.8/site-packages/sqlalchemy/sql/schema.py", line 1399, in _extra_kwargs
self._validate_dialect_kwargs(kwargs)
File "/Users/henrym/Desktop/hello_flask/env/lib/python3.8/site-packages/sqlalchemy/sql/base.py", line 290, in _validate_dialect_kwargs
raise TypeError(
TypeError: Additional arguments should be named <dialectname>_<argument>, got 'Nullable'
(env) Henrys-Air:hello_flask henrym$