flask-- database migration step on the comic pit remember

flask database migration command:

python manage.py db init
python manage.py db migrate
python manage.py db upgrade

 

1. given: KeyError: 'DATABASE_URL'

# DATABASE_URL is my code logic defined in the database address connection 
Solution: 
    Set the environment variable: set DATABASE_URL = 123 value can define 
    execute: set environment variables can see all

 

2. error: a long list of things the version number, the version number of the table mysql need to clear the migration

# Solution: 
    the Delete from alembic_version;

 

3. Navicat when the provinces to create a similar multi-level classification using visualization tools, parent_id id primary key data types must be consistent, do not point unsigned

# Error prompt: 
    of Can not the Add Foreign Key constraint A

 

4. Sometimes a field data type change in the Model, perform database migration command does not complain, but the run command ~ show create table table name - to see the type of data have not really changed successfully

# Solution: 
find Migrations / env.py file, add the following function in run_migrations_online: 
context.configure ( 
          compare_type = True,   # check the field type 
          compare_server_default = True # compare default value 
          )

 

The foreign key can not be removed successfully, you can run:

ALTER TABLE table DROP FOREIGN KEY field names;

 

Guess you like

Origin www.cnblogs.com/lutt/p/11595062.html