I'm trying to build an user registration page and facing this:
For some reason sqlalchemy forms this row for postgresql database - (null, roman, 2021-05-04)
, but I've passed in User model that id column is primary key (so NOT NULL)
I created tables in database via pgAdmin4
I have no idea why this is happening, because I used the same code but for MySQL and for SQLite and it works
models.py
class User(UserMixin, db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), unique=True, nullable=False)
registration_date = db.Column(db.DateTime, nullable=False)
def __init__(self, username, registration_date):
self.username = username
self.registration_date = registration_date
routes.py
@app.route('/register', methods=['POST', 'GET'])
def register():
form = RegistrationForm()
if form.validate_on_submit():
user = User(username=form.username.data,
registration_date=datetime.now(),
)
db.session.add(user)
db.session.commit()
flash('User was created!', 'success')
return redirect(url_for('login'))
return render_template('register.html', form=form)