2

Is there a way to make syncdb ignore a specific table?

I decided to declare a M2M twice because from one model I wanted it to appear as a simple M2M that works with filter_horizontal. In another I added a through field and show it in an inline. I used db_table to make the simple one use the same through table. This all works well usually, BUT in syncdb I always get an error the first run because it thinks it must create the table twice, but it already exists the second time. Not a problem until I get to testing which creates the test database and fails. Maybe I'm just an idiot for using this hack. Is there anyway to make Django ignore this error or specify not to create the m2m through table the second time?

Bufke
  • 3,195
  • 3
  • 28
  • 28
  • It's a creative solution to your problem; I'll give you that. But, I think you're out of luck. The only thing you can really do is monkey patch the syncdb management command, and that's never a good idea. Maybe you should add to your question what you're actually trying to achieve/why you're setting it up this way. Perhaps someone will have a better idea how to accomplish that. – Chris Pratt Jun 08 '11 at 16:58
  • can you just rename one of them throughout your project? Or are they both pulling from the same data? Doesn't seem like a good situation/design either way, but I don't have much advice for the time being. – j_syk Jun 08 '11 at 18:54
  • They are pulling from the same data. It's a quick hack to get the horizontal filter in one model, and the inline with through fields in other other. I know I could do this a more proper and time consuming way, this does exactly what I want with just one line of code. Of course if it requires patching syncdb...well then it's probably more burden than it's worth. – Bufke Jun 09 '11 at 15:57
  • Are you doing this to modify the admin functionality or are you using it in hand crafted forms? If it is an admin issue, you could probably modify the admin itself. Anyway, post your (stripped down) models.py and admin.py and we'll try to help. – Udi Jun 16 '11 at 10:06
  • related: http://stackoverflow.com/questions/1339409/how-to-add-bi-directional-manytomanyfields-in-django-admin – Udi Jun 16 '11 at 10:29
  • I am doing this specifically for admin. I've had something similar with inlines, but the problem is I don't want inlines. I just want the manytomany horizontal widget. I've thought about modifying admin but as mentioned I liked this solution that involves only one line of code. Basically I'm lazy. – Bufke Jun 25 '11 at 20:16
  • possible duplicate of [django admin many-to-many intermediary models using through= and filter\_horizontal](http://stackoverflow.com/questions/10110606/django-admin-many-to-many-intermediary-models-using-through-and-filter-horizont) – Bufke Dec 27 '13 at 19:45

1 Answers1

2

I ended up using the Model Meta option managed = False to make syncdb ignore the model. Then used initial sql data to create the sql for the table by hand. If I could tell django that only the manytomany field was not to be managed I wouldn't need to write custom SQL, but this can't be done.

Bufke
  • 3,195
  • 3
  • 28
  • 28