MySQL data types vs Django/Python data types

Fábio Santos fabiosantosart at gmail.com
Wed Sep 4 05:28:44 EDT 2013


On 1 Sep 2013 21:54, "Gary Roach" <gary719_list1 at verizon.net> wrote:
>
> Hi all,
>
> System:
>         Debian Wheezy Linux
>         Python 2.7
>         Django 1.5
>         MySql 5.5
>
> I am new to Python and Django and 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.

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, let's
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.

> 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.

Are you sure mysql is up to it? For searchable text you will want to have
an index, and while mysql's FULLTEXT kind of works, it is clearly not a
core feature. Some options for it are enabled or disabled in compile time.
Also, I won't judge but it's often wrong to use a rdbms to store
PDF/audio/video. Those belong in the file system or nosql storage.

> 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.
>
> Any help will be sincerely appreciated.
>
> Gary R.

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130904/cb232e19/attachment.html>


More information about the Python-list mailing list