Skip to content
This repository has been archived by the owner on Jun 3, 2019. It is now read-only.

Issue when trying to create user from admin panel #11

Open
utgsolutions opened this issue Feb 11, 2018 · 1 comment
Open

Issue when trying to create user from admin panel #11

utgsolutions opened this issue Feb 11, 2018 · 1 comment

Comments

@utgsolutions
Copy link

Admin Panel throws this error:
Error: Integrity error. (sqlite3.IntegrityError) NOT NULL constraint failed: users.email [SQL: 'INSERT INTO users (first_name, last_name, phone, confirmation, _password) VALUES (?, ?, ?, ?, ?)'] [parameters: ('XXXXXX', 'XXXXXXXX', 'XXXXXXXX', 0, None)] (Background on this error at: http://sqlalche.me/e/gkpj)

Debugger Output from PyCharm:
SAWarning: Column 'users.email' is marked as a member of the primary key for table 'users', but has no Python-side or server-side default generator indicated, nor does it indicate 'autoincrement=True' or 'nullable=True', and no explicit value is passed. Primary key columns typically may not store NULL.
util.warn(msg)

@phon3
Copy link

phon3 commented Mar 30, 2018

The id has been set as email on this db. In order to fix the problem I had to edit app/models.py to include a couple of changes:

class User(db.Model, UserMixin):

    ''' A user who has an account on the website. '''

    __tablename__ = 'users'
    column_display_pk = True
    form_columns = ('first_name', 'last_name', 'email', '_password')
    id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String)
    last_name = db.Column(db.String)
    phone = db.Column(db.String)
    email = db.Column(db.String)
    confirmation = db.Column(db.Boolean)
    _password = db.Column(db.String)

I moved the primary_key to an id and included a forms_colums to make sure I could display the email while creating a new user from the admin panel.

The final step I had to take was to drop the db and reinitialize.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant