我正在尝试使用this tutorial进行第一次数据库迁移。区别在于作者从头开始,而我已经有一个MySQL数据库:
mysql> SHOW Tables;
+----------------------+
| Tables_in_myflaskapp |
+----------------------+
| articles |
| users |
+----------------------+
2 rows in set (0,01 sec)
使用users
:
mysql> DESCRIBE users;
+---------------+--------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+-------------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(100) | YES | | NULL | |
| email | varchar(100) | YES | | NULL | |
| username | varchar(30) | YES | | NULL | |
| password | varchar(100) | YES | | NULL | |
| register_date | timestamp | NO | | CURRENT_TIMESTAMP | |
+---------------+--------------+------+-----+-------------------+----------------+
6 rows in set (0,01 sec)
仍然,我在app/models.py
中编写了其数据库模型:
from app import db
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(64), index=True, unique=True)
email = db.Column(db.String(120), index=True, unique=True)
password_hash = db.Column(db.String(128))
def __repr__(self):
return '<User {}>'.format(self.username)
它将包括映射到Flask应用程序的User数据库模型的users表。
我知道Alembic将数据库模型定义的数据库模式与当前在数据库中使用的实际数据库模式进行比较。就我而言,有一个以前的MySQL数据库。因此,他期望:
从产生这些自动迁移的flask db migrate
子命令的输出中,我可以了解到Alembic应该在没有数据库的迁移中包括哪些内容:
(venv) $ flask db migrate -m "users table"
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.autogenerate.compare] Detected added table 'user'
INFO [alembic.autogenerate.compare] Detected added index 'ix_user_email' on '['email']'
INFO [alembic.autogenerate.compare] Detected added index 'ix_user_username' on '['username']'
Generating /home/miguel/microblog/migrations/versions/e517276bb1c2_users_table.py ... done
但是我得到了:
(MyFlaskAppEnv) mike@mike-thinks:~/Programing/Rasa/myflaskapp$ flask db migrate -m "users table"
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.env] No changes in schema detected.
因此,迁移脚本为空。我应该担心吗?