python - 《Flask Web 開(kāi)發(fā)》 無(wú)法更新數(shù)據(jù)庫(kù)
問(wèn)題描述
學(xué)習(xí)到《Flask Web開(kāi)發(fā)》第八章時(shí),運(yùn)行代碼報(bào)錯(cuò)。后來(lái)意識(shí)到User表中新增了一列,應(yīng)該更新數(shù)據(jù)庫(kù),執(zhí)行
python manage.py db migrate -m 'initial migration'
結(jié)果報(bào)錯(cuò):alembic.util.exc.CommandError: Target database is not up to date.
這種錯(cuò)誤先前沒(méi)有遇到過(guò),網(wǎng)上找了一下也不理解。
相關(guān)代碼app/models.py:
from . import dbfrom werkzeug.security import generate_password_hash, check_password_hashfrom flask_login import UserMixinfrom . import login_managerfrom itsdangerous import TimedJSONWebSignatureSerializer as Serializerfrom flask import current_app@login_manager.user_loaderdef load_user(user_id): return User.query.get(int(user_id))class Role(db.Model): __tablename__ = ’roles’ id = db.Column(db.Integer, primary_key = True) name = db.Column(db.String(64), unique = True) users = db.relationship(’User’, backref = ’role’, lazy = ’dynamic’)def __repr__(self):return ’<Role %r>’ % self.nameclass User(UserMixin, db.Model): __tablename__ = ’users’ id = db.Column(db.Integer, primary_key = True) email = db.Column(db.String(64), unique=True, index=True) username = db.Column(db.String(64), unique = True, index = True) role_id = db.Column(db.Integer, db.ForeignKey(’roles.id’)) password_hash = db.Column(db.String(128)) confirmed = db.Column(db.Boolean, default=False)@property def password(self):raise AttributeError(’password is not a readable attribute’)@password.setter def password(self, password):self.password_hash = generate_password_hash(password)def verify_password(self, password):return check_password_hash(self.password_hash, password)def __repr__(self):return ’<User %r>’ % self.username def generate_confirmation_token(self, expiration=3600):s = Serializer(current_app.config[’SECRET_KEY’], expiration)return s.dump({’confirm’: self.id}) def confirm(self, token):s = Serializer(current_app.config[’SECRET_KEY’])try: data = s.loads(token)except: return Falseif data.get(’confirm’) != self.id: return Falseself.confirmed = Truedb.session.add(self)return True
求指導(dǎo)!!!
問(wèn)題解答
回答1:刪除了migrations文件夾里一個(gè)版本后能正常更新了。
回答2:確定 Google 過(guò) ?
Google 結(jié)果: https://www.google.com/search...
根據(jù)Google結(jié)果找到的SO 答案: http://stackoverflow.com/ques...
相關(guān)文章:
1. objective-c - ios百度地圖定位問(wèn)題2. html - css 如何添加這種邊框?3. javascript - js 有什么優(yōu)雅的辦法實(shí)現(xiàn)在同時(shí)打開(kāi)的兩個(gè)標(biāo)簽頁(yè)間相互通信?4. javascript - 關(guān)于定時(shí)器 與 防止連續(xù)點(diǎn)擊 問(wèn)題5. javascript - 求助關(guān)于js正則問(wèn)題6. javascript - node.js服務(wù)端渲染解疑7. javascript - 求助這種功能有什么好點(diǎn)的插件?8. html5 - rudy編譯sass的時(shí)候有中文報(bào)錯(cuò)9. 為何 localStorage、sessionStorage 屬于html5的范疇,但是為何 IE8卻支持?10. 微信開(kāi)放平臺(tái) - Android調(diào)用微信分享不顯示
