Add column to existing table after Schema has already been generated #1327
Unanswered
csharmatech
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
Can anyone please tell me what's the way to add a new column to MYSQL table(Table already exists). I know we can use a raw sql query to insert the new column,however I don't want to do this everytime I add a new column. I know we need to pre-define the table and schemas and its not a good practise to keep adding columns later.
When I added the new column in the models.py and tried to run my application, it does not add the new column. Seems like there is another way to add this new column. Adding columns on an empty DB works fine after defining the columns in models.py and then restarting the application.
This is my models.py. I have added the new field as "isactive" which needs to be added to table.
This is the tortoise DB connection in my main.py file
If I just restart my app with these settings, I see below logs:
/home/test/.local/lib/python3.9/site-packages/tortoise/utils.py:31: Warning: Table 'users' already exists
await generator.generate_from_string(schema)
Beta Was this translation helpful? Give feedback.
All reactions