I am developing a Flask app that queries on an existing Postgres DB. This DB had been created with Django models. Do i need to reverse engineer so my models would be compatible with SQLAlchemy or will that already be. Is raw queries the way to go? I don't want to create new DBs just query and update some values in the existing ones, that had been created in Postgres using my django models.
Go check out sqlalchemy's AMAZING automap feature: http://docs.sqlalchemy.org/en/latest/orm/extensions/automap.html
Used it once in my personal project for similar purpose, it works great.
Related
I'm creating a web app for my school to help manage and store student documents. I'm creating the app in such a way that each student in the school gets their own database to store documents (absent notes, doctor notes, etc.). I am creating this database webapp using Django and MongoDB. I'm having a hard time figuring out how to link MongoDB and Django in such a way that I can have an infinite number of databases. Ideally, I'd like to have it so that each student gets their own database filled with their own set of documents. I was just wondering how (or if it's even possible) to create an infinite number of databases and link it to Django from MongoDB? If so, how would I set up my settings.py file and my models.py file?
As of now, I have used Pymongo as a simple way to create many databases on the original MongoDB server, but haven't found an "ORM" for MongoDB that works for Django and allows me to create many databases. If MongoDB doesn't work, could I try using something else like PostgreSQL?
I have a running Django server using MySQL.I want to modify its models from another python program.
I came up with a few ideas.
Directly insert data into MySQL (will this reflect on model objects?)
Create a REST interface
I'm unfamiliar with Django's ORM, what is the right approach?
I am going to develop django rest framework apis using postgres legacy database in which apart from the existing tables no other default django tables should be created. I would like to know without creating any django default tables or doing migrations,
can i able to access records from tables using ORM?
Can i able to access admin page without creating django auth table (i.e superuser)?
If no for both questions, only way to connect to db is using any db adapter like psycopg2?
can i able to access records from tables using ORM?
If the schema is same in your models and DB tables, then yes.
Can i able to access admin page without creating django auth table
(i.e superuser)?
As far as I can tell, no, you can't get that, unless your existing 'tables' already have that, and you have all the necessary credentials.
For question in #3, I'd use something less constraining like Flask if you have these problems.
Let's say I have the following table showing how the columns would be declared for a MySQL table: (I can't think of a very realistic example, so here's something that's so silly. This table is created with the help of Excel)
I want to create a model in Django that is compatible with the MySQL table I'll have with the columns declared this way. However, from looking at the Django documentation, I can't find any model field types that in SQL are the same format as those in the picture except for the primary key field.
I did see before that by default, Django handles a database that uses the SQLite Engine, but I want to see if it's possible to handle a database of MySQL tables.
Is there a way to create Django model field types, like MEDIUMINT, TINYTEXT, and SMALLINT, (in MySQL) that are compatible with tables created through MySQL? It's simply a way for me to use the tables that I created myself, not the tables that Django generates automatically once all the models are defined.
In Django you normally create the models and let the framework generate the tables for you. If you have a legacy database you can use python manage.py inspectdb to generate the models from the database (see the documentation). But if it isn't a legacy database and you've created it just now, you are fighting against the framework and making your life more complicated.
I have experience programming in python, but am new to Django. I recently went through the tutorial and eveything made sense, however I am wondering if I can create views from DB tables that already exists without having to create models. Or, if this isn't possible is there a way to create models to generate an ORM with a DB table that already exists?
Basically I have Aggregate metrics in data warehouse tables that I would like to publish to a web page in real time. Is Django the right tool for this? Thanks.
Use ./manage.py inspectdb to create models from an existing database.