0

数据库 example.db 已创建但生成错误!!!


回溯(最后一次调用):文件“db_testing.py”,第 39 行,在 admin.save()
文件“C:\Users\dell\Envs\surveyApp\lib\site-packages\peewee.py”,第 2405 行,在保存 new_pk = insert.execute()
文件“C:\Users\dell\Envs\surveyApp\lib\site-packages\peewee.py”,第 1721 行,执行 return self.database.last_insert_id(self._execute( ), self.model_class)
文件“C:\Users\dell\Envs\surveyApp\lib\site-packages\peewee.py”,第 1420 行,在 _execute 中返回 self.database.execute_sql(sql, params, self.require_commit)
文件“C:\Users\dell\Envs\surveyApp\lib\site-packages\peewee.py”,第 1824 行,在 execute_sql res = cursor.execute(sql, params or ()) sqlite3.IntegrityError: column email is not独特的

代码

import datetime
from flask import Flask
from flask_peewee.admin import Admin
from flask_peewee.auth import Auth
from flask_peewee.db import Database
from peewee import *

# configure our database
DATABASE = {
    'name': 'example.db',
    'engine': 'peewee.SqliteDatabase',
}
DEBUG = True
SECRET_KEY = 'ssshhhh'

app = Flask(__name__)
app.config.from_object(__name__)

# instantiate the db wrapper
db = Database(app)

# create an Auth object for use with our flask app and database wrapper
auth = Auth(app, db)
admin = Admin(app, auth)

class Note(db.Model):
    message = TextField()
    created = DateTimeField(default=datetime.datetime.now)

admin.register(Note)
admin.setup()

if __name__ == '__main__':
    auth.User.create_table(fail_silently=True)
    Note.create_table(fail_silently=True)

    admin = auth.User(username='admin', email='aoeu@gmail.com', admin=True, active=True)
    admin.set_password('admin')
    admin.save()
    app.run()  

使用示例

http://flask-peewee.readthedocs.org/en/latest/getting-started.html#setting-up-a-simple-base-template

4

1 回答 1

0

数据库已经创建,删除以前的数据库解决了

于 2013-08-11T07:17:36.530 回答