Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect Django to external DB without migrations

I would like to connect my DjangoApp to an external MySQL database. I don't want to make migrations to this table, I mean I don't want to create new tables ,just pull data. And my question is - how to do this ? If i add this table to DATABASES in my settings file then the console shows an error about mandatory migration.

What can you recommend me ? Thanks in advance,

like image 967
Vba_Beg Avatar asked Oct 26 '25 21:10

Vba_Beg


1 Answers

you can connect to the external database with this

settings.configure(
DATABASE_ENGINE = 'mysql',
DATABASE_NAME = 'db_name',
DATABASE_USER = 'db_user',
DATABASE_PASSWORD = 'db_pass',
DATABASE_HOST = 'http://YourDataBaseAdress.com/mydatabase',
DATABASE_PORT = '6676',
TIME_ZONE = 'America/Sao_Paulo',) //if you want to connect this forever add this
'CONN_MAX_AGE': None,

and with for no migration you can do

class Meta:
    managed = False

in your specific model.

for pulling data from external databases you can see here

like image 168
Kalariya_M Avatar answered Oct 29 '25 10:10

Kalariya_M



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!