top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

MySQL data types vs Django/Python data types

0 votes
579 views

I am having trouble matching Python data types with those of MySQL. MySQL has about 7 basic data types including Blobs, Binaries, etc. It also has a rich selection of geometry types. In addition, types like INT have 7 or 8 different options like Primary Key, zero fill, auto inc, etc. I can't seem to find anything in python to match these. I am trying to build a model.py for an existing database that was created with MySQL Workbench.

I do not wish to use anything other than MySQL because of the complexity of my storage needs (searchable text, PDF, Audio, Video and Photos). The text searches will often be word phrase searches through thousands of documents. I need the speed and the data type flexibility.

How do I build or modify a model.py to do this. I really don't want to write a model.py manually. That would really be a major pain. Workbench to the database an import to Django and edit is my choice. Unfortunately, the model.py produced has lost most of the functionality of the original database and I can't seem to figure out how to fix it.

posted Sep 1, 2013 by Salil Agrawal

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

1) First, I want to state that you need to understand that Django was designed to help build simple, common use case web apps. Database skins, as someone put it. The ORM is very easy to use, although it is not well prepared for some things.

It also has a very nice advantage, which is being compatible with many RDBMS so you can have postgresql on the production server and sqlite on your development machine. This ends up being bad too. For instance, if it is not possible to do something in a specific rdbms, for instance, lets say blobs, Django will not be able to implement it because it has to support those several rdbms.

There are many hacks ( http://djangosnippets.org/snippets/1597/ ) but hacks will be hacks and you want your app to be reliable and not compromise your code quality right from the start, right?

Many field options have equivalents in Django (primary key, auto increment). You just have to find them. For auto increment there is AutoField. Primary key is an option of the base Field (so you can provide it as a keyword argument to any field).

Also if you want gis geometry data types (is that what you meant?) you can install and use geodjango.

2) A lot can be done by using the database manually. Django helps you a bit here, for instance it gives you access to the database cursor for raw SQL access to the database, supports custom fields, and every orm query "chain" (like MyModel.objects.all().filter(...)) can be incremented with raw SQL "where" and "select" clauses. But you might not want to be using Django or at least not its ORM.

answer Sep 4, 2013 by anonymous
Similar Questions
0 votes

I'm new to Django. Is there any tell how to add a limit filter in Django?

+2 votes

I am trying to learn Django. My initial exercise seems fine. I want to create an API with REST on Django for an interactive Python code. REST framework on Django I am understanding more or less.

I am looking for a simple example to start with. I am using Python 2.7+ on MS-Windows 7 Professional.

If any one may kindly suggest.

+4 votes

I have been trying to set up a python, django, mysql, virtualenvwrapper and git development project and am really confused. All of the documentation seems to ignore the apt-get installation methods used by Debian Linux and its derivatives. Does pip install the same as apt-get; I don't think so. If I use virtualenvwrapper, how does this fit with the normal debian (wheezy) installation. I also need git which just confuses the situation even more. Must I give up the automatic updating system that Debian provides when setting up the development environment?

The documentation centers on Windows, Mac and generic Linux distributions and ignores the automation of the Debian installation. All of the documentation I have found concentrates on the installation of individual packages or on the use of python-django and is very sketchy on the overall virtualenv(wrapper), git, python-django file structure and installation order.

+1 vote

Is it possible to display a data grid table with django? Basically I am looking for displaying a data from the db table on the web interface through django or some other web interface.

My main application is in Python, that's why I'd like to explore Python possibilities first.

0 votes

Can anyone help me to generate SQL query from Django query

  • Like below:

Employee.objects.all() => select * from employee

...