I have an interesting scenario for work. I have an older legacy mysql database running 5.7.42 that I have no control over and would like to use as a read-only database for support research. Our team is constantly in the legacy system (which is a production r/o clone) and pull data for research all day. I can use a local mysql for normal admin functions, etc. if needed.
Is there any way for me to setup Django with this type of setup? I know there are options for read-only but I could not seem to get past the version being older and wasn’t sure if this is doable. If not I’ll look at other solutions. My goal is to take the crazy sql we write all day to research data from production and start setting it up with re-usable django models/queries so we can easily repeat a ton of steps we do everyday manually with sql.
I have the ability to potentially write back-end modules to get data from the legacy, and write to local db, but that just adds a ton of work and I’d much rather setup models for my legacy to pull data. Thanks!
Absolutely. See the docs for Multiple databases. This is something we do quite regularly.
Set up a database definition for the legacy db, create your models with “managed=False” (and other parameters as necessary), and create a router so that references to those models access the legacy db. You can also create the router to reject attempts to update the data in those models.
(If you really want to be safe about it, make sure you’re given a set of credentials to that database that don’t have any insert or update permissions.)
ok thanks Ken! Glad this sounds promising. I kept hitting a wall before when Django connected and told me it was an usupported version. It will work with 5.7.42?? And as long as it isn’t setup as the ‘default’ database it seems like this should work? i did not think the latest django release would communicate with the older mysql version regardless of whether it is read-only routing, etc.
@KenWhitesell fyi - I just setup 2 dbs and getting this error which is what i hit before
django.db.utils.NotSupportedError: MySQL 8.0.11 or later is required (found 5.7.42). Does this only fail perhaps for db tools like “inspectdb” (which is what i did that caused error) perhaps but normal read functions will ignore the version??
No, unfortunately I’m inclined to believe that if the Django database engine is being that strict with the versions, you’re probably out of luck.
You could try making your own version of the database engine class to remove the version test, and use that as the additional database engine. (I would try with making the change in the
minimum_database_version function in
No idea if it will work, or if it would cause problems with issuing queries. But if it’s something you absolutely want to try…
ugh. what a bummer. i was really hoping i could easily work around this.