Question

Here is my situation. I used Python, Django and MySQL for a web development.

I have several tables for form posting, whose fields may change dynamically. Here is an example.

Like a table called Article, it has three fields now, called id INT, title VARCHAR(50), author VARCHAR(20), and it should be able store some other values dynamically in the future, like source VARCHAR(100) or something else.

How can I implement this gracefully? Is MySQL be able to handle it? Anyway, I don't want to give up MySQL totally, for that I'm not really familiar with NoSQL databases, and it may be risky to change technique plan in the process of development.

Any ideas welcome. Thanks in advance!

Was it helpful?

Solution

You might be interested in this post about FriendFeed's schemaless SQL approach.

Loosely:

  • Store documents in JSON, extracting the ID as a column but no other columns
  • Create new tables for any indexes you require
  • Populate the indexes via code

There are several drawbacks to this approach, such as indexes not necessarily reflecting the actual data. You'll also need to hack up django's ORM pretty heavily. Depending on your requirements you might be able to keep some of your fields as pure DB columns and store others as JSON?

OTHER TIPS

I've never actually used it, but django-not-eav looks like the tool for the job.

"This app attempts the impossible: implement a bad idea the right way." I already love it :)

That said, this question sounds like a "rethink your approach" situation, for sure. But yes, sometimes that is simply not an option...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top