简体   繁体   English

sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) NOT NULL 约束失败:user.id

[英]sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) NOT NULL constraint failed: user.id

I get an error when I try to add data to the database.当我尝试将数据添加到数据库时出现错误。 I've set up the data base and it's application我已经建立了数据库及其应用程序

class User(db.Model):
    id = db.Column(db.Integer,primary_key=True)
    name = db.Column(db.String(120),nullable = False)
    email = db.Column(db.String(70),primary_key=True,nullable = False)
    post = db.Column(db.String(10000),default ="")
    date_created = db.Column(db.DateTime, default = datetime.utcnow)

    def __repr__(self):
        return f'{self.id},{self.name},{self.email},{self.post},{self.date_created}'

And I get issues whenever I try to create the database in the code below:每当我尝试在下面的代码中创建数据库时都会遇到问题:

@app.route('/sign_up',methods = ["POST","GET"])
def sign_up():
    if request.method == 'POST':
        email = request.form.get('email')
        first_name = request.form.get('first_name')
        password_1 = request.form.get('password')
        password_2 = request.form.get('password-2')

        user = User.query.filter_by(email=email).first()

        if user:
            flash("Email aleady exists", category = 'error')
        elif len(email) < 5:
            flash("Email name must be greater than 5 characters", category='error')
        # We'll come back to you tomorrow (i.e 25th March)
        elif len(first_name) < 2:
            flash("First Name too short",category='error')
        elif password_1 != password_2:
            flash("Make sure you typed the password correctly",category='error')
        elif len(password_1) < 8:
            flash("Make sure your password as at least 8 characters", category='error')
        else:
            new_user = User(name= first_name,email = email)
            db.session.add(new_user)
            db.session.commit()
            flash("Account Created",category='success')
            return redirect(url_for('home'))

    return render_template("sign-up.html")

Update table in Postgresql.更新 Postgresql 中的表。 make the ID auto increment .使 ID自动递增

or supply the id with data ( deprecated )或为 id 提供数据(已弃用)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) NOT NULL 约束失败 - sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) NOT NULL constraint failed sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) NOT NULL 约束失败:user.words - sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) NOT NULL constraint failed: user.words 使用 flask sqlalchemy.exc.IntegrityError 时出错:(sqlite3.IntegrityError) UNIQUE 约束失败 - Error when working with flask sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) UNIQUE constraint failed sqlalchemy.exc.IntegrityError:唯一约束失败 - sqlalchemy.exc.IntegrityError: UNIQUE constraint failed sqlalchemy.exc.IntegrityError - sqlalchemy.exc.IntegrityError 烧瓶-(sqlite3.IntegrityError)NOT NULL约束即使在迁移后也失败 - Flask - (sqlite3.IntegrityError) NOT NULL constraint failed even after migration 表未监听其他表中外键设置的值,IntegrityError: (sqlite3.IntegrityError) NOT NULL 约束失败 - Table not listening to value set for foreign key in other table, IntegrityError: (sqlite3.IntegrityError) NOT NULL constraint failed django.db.utils.IntegrityError: NOT NULL 约束失败:user.id - django.db.utils.IntegrityError: NOT NULL constraint failed: user.id 为什么我收到sqlalchemy.exc.IntegrityError - Why I receive sqlalchemy.exc.IntegrityError web2py:sqlite3.IntegrityError&#39;&gt;(外键约束失败) - web2py: sqlite3.IntegrityError'>(foreign key constraint failed)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM