python - 《Flask Web 開發(fā)》 無法更新數(shù)據(jù)庫
問題描述
學(xué)習(xí)到《Flask Web開發(fā)》第八章時,運(yùn)行代碼報(bào)錯。后來意識到User表中新增了一列,應(yīng)該更新數(shù)據(jù)庫,執(zhí)行
python manage.py db migrate -m 'initial migration'
結(jié)果報(bào)錯:alembic.util.exc.CommandError: Target database is not up to date.
這種錯誤先前沒有遇到過,網(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)!!!
問題解答
回答1:刪除了migrations文件夾里一個版本后能正常更新了。
回答2:確定 Google 過 ?
Google 結(jié)果: https://www.google.com/search...
根據(jù)Google結(jié)果找到的SO 答案: http://stackoverflow.com/ques...
相關(guān)文章:
1. javascript - 請問 chrome 為什么會重復(fù)加載圖片資源?2. (python)關(guān)于如何做到按win+R再輸入文件文件名就可以運(yùn)行?3. mysql - 分庫分表、分區(qū)、讀寫分離 這些都是用在什么場景下 ,會帶來哪些效率或者其他方面的好處4. python - 能通過CAN控制一部普通的家用轎車嗎?5. javascript - react input file6. javascript - 請教如何獲取百度貼吧新增的兩個加密參數(shù)7. css3 - 微信前端頁面遇到的transition過渡動畫的bug8. Python爬蟲如何爬取span和span中間的內(nèi)容并分別存入字典里?9. html5 - 只用CSS如何實(shí)現(xiàn)input框的寬度隨框里輸入的內(nèi)容長短自動適應(yīng)?10. javascript - 關(guān)于css絕對定位在ios瀏覽器被橡皮筋遮擋的問題
