0

I am trying to migrate data from a node.js app to my django app, luckily they both use postgresql but I don't know how the access the node.js database and get the model, I have entered the second database in my settings.py but .get_model() cant take database name as an attribute only app name and model name, and since the app is in node.js I am running in a problem before even starting, is there a way to get the model directly from the node.js side database and what is the syntax ? this is my code so far:

class Migration(migrations.Migration):

def migrate_items(self, schema_editor):
    old_item_model = self.get_model("inventory", "Item")  # THIS NEEDS TO COME FROM THE NODE.JS SIDE DATABASE.
    items = old_item_model.objects.using('inventory').all()
    print(items)

def reverse_migrate_items(self, schema_editor):
    pass

dependencies = [
    ('items', '0022_merge_0020_alter_history_event_0021_alter_assign_item'),
]

operations = [migrations.RunPython(migrate_items, reverse_code=reverse_migrate_items)
]

Thanks.

miloshIra
  • 53
  • 5
  • 1
    Does this answer your question? [Create model for existing database table in django](https://stackoverflow.com/questions/57557290/create-model-for-existing-database-table-in-django) – Abdul Aziz Barkat Nov 01 '22 at 17:14
  • Also read the documentation on [How to integrate Django with a legacy database](https://docs.djangoproject.com/en/4.1/howto/legacy-databases/) – Abdul Aziz Barkat Nov 01 '22 at 17:15
  • They return the model I wrote from my defalult database, not the ones I need from the node.js side database. Spoke too soon, I saw I can use --database DATABASE to select the database I want. Thx. Let's see how far it gets me. – miloshIra Nov 01 '22 at 17:46

0 Answers0