I am using sqlite database and I declare the model as this:
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
login = db.Column(db.String(80), unique=True)
password = db.Column(db.String(64))
def is_authenticated(self):
return True
def is_active(self):
return True
def is_anonymous(self):
return False
def get_id(self):
return self.id
# Required for administrative interface
def __unicode__(self):
return self.username
And I have add a Model instance like this:
admin = admin.Admin(app, 'Example: Auth', index_view=MyAdminIndexView(), base_template='my_master.html')
admin.add_view(MyModelView(User, db.session))
db.drop_all()
db.create_all()
if db.session.query(User).filter_by(login='passport').count() <= 1:
user = User(login = 'passport', password = 'password')
db.session.add(user)
db.session.commit()
However, if I comment the db.drop_all(), it will occur an error which is:
sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) UNIQUE constraint failed: users.login [SQL: 'INSERT INTO users (login, password) VALUES (?, ?)'] [parameters: ('passport', 'password')]
And if do not comment the db.drop_all(), everything is fun. Because there are other tables on this database, I do not want to drop all the tables when I run it. Are there any other solutions to fix that?
Thanks a lot.