Home > OS >  How to change the database local to be in a cloud (Django)
How to change the database local to be in a cloud (Django)

Time:05-02

I wrote a project in django framework and I use the local DataBase SQLite, and I now want to upload it to the cloud so other people who work with me can access DataBase i.e. when I create a user then that user will exist with my co-workers.

Maybe someone has a guide on how to do this without modifying the DataBase so that I do not have to modify the rest of the code?

CodePudding user response:

Ok i found the answer, what you should do is Connect Django and MongoDB Using Djongo

you can read from enter image description here

  • press on Connect buttom enter image description here
  • choose "Connect your application" and then choose python and the last version
  • after all this you will have this link: for example!!!

    mongodb srv://<username>:<password>@<atlas cluster>/<myFirstDatabase>?retryWrites=true&w=majority
    

    copy this link and do the next setps:

    • go back to your terminal and install this package: pip install djongo
    • and open settings.py
    • change your DATEBASE to like this:
    DATABASES = {
            'default': {
                'ENGINE': 'djongo',
                'NAME': 'your-db-name',
                'CLIENT': {
                    'host': 'mongodb srv://<username>:<password>@<atlascluster>/<myFirstDatabase>?retryWrites=true&w=majority'
                }  
            }
    }
    
    • in 'host' paste the link you copy from monogodb site.
    • in 'NAME' write your name of the database.

    Now that we have the Django project (and app), you can create the collections in MongoDB using the commands:

    python manage.py makemigrations <app-name>
    
    python manage.py migrate
    

    if you get error like 'django.db.utils.databaseerror' what you should to do is: It deletes all the files that are in the migrations folder that are in the apps you have created and after that run again the command above.

    • Related