Friday, January 30, 2015

Re: using Django on an existing mysql schema


On Fri, Jan 30, 2015 at 10:47 PM, William Muriithi <william.muriithi@gmail.com> wrote:
‎Hello,

I am new to Django and planning to use it for a project I have in mind. I am strong in mysql, but not too good in developing. In fact, the secondary purpose of this project is to improve my python development skills.

With such a background, I went about doing my data modeling and then set up views on top to de normalize the underlying schema and pushing most of the business logic in mysql. I want to use Django mainly to insert and display, which increases the chance of success with few bugs.

Problem is, with Django, it seems things are done the other way around. After playing with it, I noticed it changes the keys from unsigned to signed, something I feal is bad from database point of view. It converted enum to char, which to me is less appealing. In short, I don't like the change its introducing. ‎

My question is, can one use Django with an existing database without getting in trouble with the framework? I believe this has to be possible somehow as most companies work from data backwards. Would appreciate a good advice on how you guys and girls went‎ about using Django from existing schema. Or a Django book that take that perspective. The once I have read advice me to leave database work to orm.

Yes, you can. Django's ORM is there to make your life easier, but there's no requirement that you use it to create your tables, or even to execute queries. There's an inspectdb management command to help build wrapper models for your database; but if you want, you can avoid the ORM entirely, and use raw database cursors to talk directly to the database. 

Of course, if you do this, you're going to miss out on at least some of the power of Django. 

For example, Django has a forms library, which is quite powerful. You can use it without using Django's ORM. However, if you *are* using Django's ORM, you can use ModelForms, which is a way to automatically generate a form for a model.
 
You're also going to miss out on the community of apps that are out there to help you get functionality running easily. For example, if you don't have Django ORM models, then Django's admin interface wont work. A lot of the power of Django is that it has a good "meta" understanding of the data in the database; if you take that away, then the functionality that relies on it obviously wont work.

There's nothing inherently wrong with this - you can code everything yourself if you want and treat Django as little more than a request routing library. The only problems you're going to experience are related to the fact that documentation out there will generally assume that you're using Django models, not rolling your own. My only concern is that this might leave you with an odd perception of the capabilities of Django.

Yours,
Russ Magee %-)


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJxq84-Vf5iTNxH-B2FGnS1sTxT-UA0V%3D4o5axLw_K%2BGpEf%3Dtw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment