How do I prevent my Django Database from being overwritten - django

Currently I have a Django application running on my personal website from PythonAnywhere.com. When I make updates to the site I login to PythonAnywhere and git pull to update my application. When I do this the data that was entered through the website since the last update gets lost from the database when I update. What can I do to overcome this?
I am currently using the SqlLite version that comes preinstalled with the Django App. This likely could be part of the issue but need some help understanding how to overcome it.

I presume that your Django project is connecting to the SQLite database that gets generated when you create a new project and you are pushing that database in your deployment. That database won't be suitable for production and won't retain your changes, you instead need to setup a database that your application can connect to.
Here is some information on PythonAnywhere about databases:
https://help.pythonanywhere.com/pages/KindsOfDatabases/
And the Django documentation:
https://docs.djangoproject.com/en/4.0/ref/databases/

Related

how to do makemigrations/migrate in gnadi(python/postgresql web hebergement)

I am a python developer and new to GANDI (python/PostgreSQL web hosting). There is no document to migrate databases to their server. they have their document to deploy a Project Django but not very clear there are a lot of things missing. After taking a lot of time on the internet, I managed to deploy a Django project in their server. The site works smoothly with an SQLite database. Now I would like to make a Django Project with PostgreSQL. I have an emergency console, but I would like to work locally and then I would like to migrate the DBs to their phpPGadmin server. I just need your help to do makemigrations/migrate to thier PostgreSQL(PhpPGadmin) server. Thanks in advance.

where is the data saved during Django stack development

Maybe this is a super silly question. I am new with Django stack web app development.
I am following Django tutorial on MDN. I entered information to the backend database via the admin page. But some error happened later so I had to uninstall pyenv and restart. I wonder if I can find all the information I entered which is not on any project documents. Thanks.
Assuming you're following the tutorial closely and they don't specify a database to store information in, there should be a sqlite3 database in your project file system

When deploying updated Django code on server, the database resets

I have built an app which uses Django as a Rest API (Django rest framework). After having deployed the code on digital ocean using production grade services, everything works well. The postgresql database populates itself correctly . There is no reset of the server like on Heroku.
Except, if I change a file and push the change through gitlab(Digital ocean picks up the change and automatically deploys the updated version of the server), the database resets to its original state. I would like the server to stay as.
I have removed all migration files before pushing updates, but to no avail. I imagine it has to be something rather trivial but I can't find it.
The database is hosted also by digital ocean. I havent done any configuration. Wouldn't it be managed automatically as DO deploys the code on its servers?
I figured out what went wrong. Using the sqlite db while developping is one thing, but assuming when deploying your django app on a service provider that it will handle the whole db management is a 1000 steps too far.
Logically, whenever I pushed a new update to the server, the db would reset using the sqlite local db file of the project.
So I created a specific db on digital ocean, change the database config on the settings file of my django project to connect to it. Making the project use the external db. then I Just had to migrate project db structure to the external db.
And Voila. problem resolved

What is the best Workflow for Updating a Web App

I'm pretty new at this but I recently deployed my first web application using Django, Postgres, Nginx, and Gunicorn on Digital Ocean.
I went to make some updates and ran sudo service gunicorn restart to see the changes. I wiped my entire Database. I obviously need to work on setting up a better workflow for deploying to production.
Does anyone have any suggestions? What are some best practises when re-deploying a Django App with a Postgres DB? I've read some articles about backing up my DB (which I'm definitely going to be doing in future), but what else can be done to ensure a seem-less transition?

Set up an existing Django app on another server

This must, must, must be a duplicate but I can't find the answer either here or on Google.
I have an existing Django app and I want to deploy it on another server.
What are the steps I need to go through to get it running elsewhere, in words of one syllable?
At a minimum, presumably:
create a project on the new server
copy over all my app's files into that project
edit localsettings.py or equivalent with local database settings etc
run python manage.py syncdb to create my database
load fixtures
run tests
Is that it? Are there any unofficial or official instructions for copying an app elsewhere?
Thanks.
The most basic, easy way to do it is:
Set up the server environment so that it matches the current environment as closely as possible. The most important thing is that you're using the same version of Django (obviously). You can run a different database, but it makes porting from the old server to the new server a little more involved. Otherwise, you will just have to adjust your settings to match the new server, if they can't be duplicated (ie, user names, etc).
Copy over your code
Dump your old database structure and data into the new database
Running startproject isn't strictly necessary. Your web server just needs to be configured correctly, to run django with the appropriate settings.py file -- and Django takes it from there.