Conversion and import of a pre-existing database

34 views
Skip to first unread message

Jérémy Garniaux

unread,
Jan 7, 2021, 9:13:53 AM1/7/21
to django...@googlegroups.com
Hi,

I'm working on my first Django project. Already read the tutorial but
following along it to be sure not to miss anything.

I've been asked to rebuild a pre-existing website. It's basic in
functionality: various users create complete descriptions of heritage
items in the admin area, and the public page display the description,
mostly in text format, sometimes with images too. The final user can
navigate the items on the public page.

The data model contains many different classes and variables - it's well
structured and doesn't need to change.

The data is stored into a MS SQL Server database. The new website will
use PostgreSQL, so I need to convert the MSQSQL database and import it
into PostgreSQL. I'm aware of inspectdb but I decided to manually write
models.py from the ground to get acquainted both with the data and with
django models.

What I'd like to know is:

- Should I work on the conversion and import of the MSSQL database into
PosgreSQL without thinking about Django at this stage?

- I read that Django will add "_id" at the end of the field names.
Should I worry about that? Or should I leave in PgSQL the same field
names there was in MSSQL? How should I name my variables in models.py then?

- Any other advice will be very welcome :)

Thanks a lot for your help,

Jeremy

Peter van der Does

unread,
Jan 7, 2021, 9:58:36 AM1/7/21
to django...@googlegroups.com

Jérémy,

It all depends on the Database which route to take. Is it one table, multiple tab;es, what are the relationship?

My plan of attack would be:

  1. Create all models in Django as you want them to be. Use the Django standards to name your new fields [1].
  2. Let Django handle the field naming, unless you have a really good reason to overwrite this behavior. Relationships are setup to other models, do not add _id to these fields, Django 
  3. Create the migrations to create the models in Postgres
  4. With Django in mind write your conversion. In other words, use the Django ORM to write data to your new DB, while using RAW sql to read the old DB.
  5. Write the conversion as management command.
  6. If you have multiple tables start filling the tables that do no have any relationship to other tables first and work your way up. No FK Tables-> Tables with one or more FK to an already existing table


[1] - https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/coding-style/#model-style

gabriela...@gmail.com

unread,
Jan 7, 2021, 10:27:15 AM1/7/21
to Django users
Perhaps there is a utility program that can do that. Something like converter. Have you look in web foros  ?
Reply all
Reply to author
Forward
0 new messages