Using DB without modifying it - Django - django

I need to connect to a Postgresql server in my Django project. But I'm under strict instructions NOT to make any modifications to the database or tables.
If I'm not wrong, simply adding this DB to settings.py and running syncdb would create and add some django specific tables to the database.
How can I get around this issue? If I add another (local) sqlite DB to settings.py under default and my remote postresql server separately; can I be sure of Django not creating any tables in my server? I couldn't find this info in the documentation.
Thanks

Configure two databases in settings.py, and a create database router to route your queries to the appropriate database.
Route all the Django admin / users stuff to your sqlite database (make it the default database, and make sure that is indeed the one your router returns by default), and single out your application queries that need to go to the Postgres database.
Routers also have a method to locate a DB for writes and one for reads, so you can use this as a failsafe: just make sure db_for_write never returns your Postgres database, and you're good to go.

Related

Django transfer database to different Django project without messing up the logic

I built a Django project with a few models. Now I created a second server with the same setup. This one is meant to be the deployment server. Databases are separate from the dev-server.
However can you tell me if I can simply copy the databases from the dev server to the deploy or will the Django logic, since I also mean the user models and permissions etc.
The tables which I created myself are no problem to transfer to the new server. However I am wondering If Django gets confused when I also transfer something like the auth_user Model.
Should this work since I also just copied the backend logic as well?

Detect database DDL schema changes with Django

Let's say that we have a Django app that looks on a legacy database.
If someone make changes on some database tables from a db client as DBeaver for example and not through Django models, is there a way to identify these changes?
You can do in a terminal, inside your Django project directory : python manage.py inspectdb > models.py
You will have models related to your tables.
By default, inspectdb creates unmanaged models. That is, managed = False in the model’s Meta class tells Django not to manage each table’s creation, modification, and deletion.
If you do want to allow Django to manage the table’s lifecycle, you’ll need to change the managed option above to True (or remove it because True is its default value).

Implement LiteSync on Django

I've tried to write sync sqlite database between 2 different Server but same app and DB. But when i turn on litesync.io in console, it doesnt synchronize the Django project with Django project in another server. I know it's wrong because i must configure it first in django project, but i've tried to change NAME of DATABASES into URI and it not work. I've tried it in console to execute query, it works, but not in Django Project. So, how to implement litesync on Django project? How to save data into Sqlite DB by URI?

Migrate users from database to another on Django

I already have an existing website running and want to transfer just the users (usernames, passwords and emails) to another database for a separate Django website as I am rebuilding it.
You can configure both databases in your django configuration file. select the user data from one database and then put the records in the other.
Multiple Databases in Django.
Moving an object from one database to another

django sync db to get two apps in two databases

I'm not sure how it works but I need two different models/apps in separated databases. So if I try syncdb --database db1 will get all installed apps into db1. So question is how to get just one app in another db?
Thanks
You need to write a database router which will filter models based on application and database in its allow_syncdb method. You cas start from the AuthRouter example in the documentation.