3

i am creating a database using SQLAlchemy and I Need to do Migration to my data as i am using df_sql function for converting my csv into dataframe and then to tables in sqlalchemy. As i do this i need to do Migration to add new column and values inside it and assign Primary and foreign key Features. I saw someting related to Alembic and flask but am not sure how to upgrade it as also am working on Jupyter. Any ideas of how i can update delete and assign keys to my tables would be very helpful. Done until the table creation.

metadata.tables.keys()

dict_keys(['table1', 'table2'])

I also tried directly to create a temp table and copy ist values and assinging Primary key but am getting error with my column names as it has Special characters so i cant create duplicate too. Rename property too doesnt work

Column: date
Column: time_stamp
Column: timeslices[5].profilerDataProcess[8]_C0[us]
Column: timeslices[4].profilerDataProcess[54]_C0[us]
Column: timeslices[4]profilerDataProcess[50]_C0[us]
Column: timeslices[4].profilerDataProcess[49]_C0[us]
Column: timeslices[0].profilerDataProcess[14]_C0[us]
shankar ram
  • 157
  • 1
  • 13
  • is you're using SQL alchemy - you can simply use `db migrate` whenever you update your models – Denis Tsoi May 29 '20 at 14:32
  • @DenisTsoi Is that an attribute of sqlalchemy or do i need to use flask with alchemy. Also can i also do the df_sql using flask? – shankar ram May 31 '20 at 19:17
  • 1
    https://flask-migrate.readthedocs.io/en/latest/ if you’re using flask, add flask-SQLAlchemy, you can use the command flask db migrate to upgrade changes to your db models – Denis Tsoi May 31 '20 at 20:55
  • 1
    Alternatively, you can write the migration script yourself via SQLAlchemy – Denis Tsoi May 31 '20 at 20:56
  • @DenisTsoi thankyou. but a final Question as i am new to using this. Since i am using Jupyter Notebook where i create database and insert data using cvs as tables. Where could i develop the Migration script? Should i do it in the application directtory and run it in the command prompt ? – shankar ram Jun 02 '20 at 07:59
  • 1
    each time you change the models, flask-sqlalchemy will automatically detect the changes based on the previous version of the models by running `flask db migrate`. You should run the command in the application directory rather than in the jupyter notebook. `flask db init` is the command to create the init scripts – Denis Tsoi Jun 02 '20 at 08:46
  • Did any of the comments help? Can provide an answer – Denis Tsoi Jun 10 '20 at 15:05
  • Actually it does not suit my Scenario where i created models using pd.real_csv function and i cannot define Primary key when defining models. So it is no possible to migrate it after creation it seems – shankar ram Jun 15 '20 at 07:05

0 Answers0