[PYTHON] When changing the table name with flask_migrate

If you use flask_migrate to change the table name in your python code, be sure to do db migrate / db upgrade.

For example

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True)
    description = db.Column(db.String(120), index=True)
    def __repr__(self):
        return '<User %r>'%self.username

And after defining the table using Flask_SQLAlchemy,

class UserData(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True)
    description = db.Column(db.String(120), index=True)
    def __repr__(self):
        return '<User %r>'%self.username

If you change the table name (class name) like

flask db migrate
flask db upgrade

I have to

sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) relation "user_data" does not exist

I get angry with "I don't have a table!" Just because you changed it in your python code doesn't mean that it implicitly changes it. It seems that you need to explicitly do flask db migrate / flask db upgrade. It looks like git.

Recommended Posts

When changing the table name with flask_migrate
When the variable name conflicts with the Devaga command in pdb
Behavior when returning in the with block
[Python] Get the variable name with str
(Note) Importing Excel with the same column name
[Automation] Extract the table in PDF with Python
Rewrite the name of the namespaced tag with lxml
[Introduction to Python] What is the important "if __name__ =='__main__':" when dealing with modules?
When a local variable with the same name as a global variable is defined in the function
Extract the table of image files with OneDrive & Python
Make Fatjar by changing the main class with Gradle
Specify the file name when sending the csv attached mail
Change the movement by changing the combo box with tkinter
Identify the name from the flower image with keras (tensorflow)
Load the module with the same name in another location
Check when the version does not switch with pyenv
A story about changing the master name of BlueZ
[Python] How to rewrite the table style with python-pptx [python-pptx]
Display the graph while changing the parameters with PySimpleGUI + Matplotlib
Specify the project name of docker-compose with Docker integration of Pycharm
Display only the resources created when acquiring AWS resources with Boto3
Solution when the image cannot be displayed with tkinter [python]
Precautions when outputting to BigQuery table every hour with Luigi
When you access the web server, L Chika with Arduino
Multiply the x-axis value by n when plotting with pylab
Try to decipher the garbled attachment file name with Python
Get the host name of the host PC with Docker on Linux