views:

93

answers:

2

When I include a ModelToModelField to one of my models the following error is thrown.

Traceback (most recent call last):
File "manage.py", line 11, in <module>
    execute_manager(settings)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 362, in execute_manager
    utility.execute()
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 303, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 195, in run_from_argv
    self.execute(*args, **options.__dict__)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 222, in execute
    output = self.handle(*args, **options)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 351, in handle
    return self.handle_noargs(**options)
File "/Library/Python/2.6/site-packages/django/core/management/commands/syncdb.py", line 93, in handle_noargs
    cursor.execute(statement)
File "/Library/Python/2.6/site-packages/django/db/backends/util.py", line 19, in execute
    return self.cursor.execute(sql, params)
File "/Library/Python/2.6/site-packages/django/db/backends/mysql/base.py", line 84, in execute
    return self.cursor.execute(query, args)
File "build/bdist.macosx-10.6-universal/egg/MySQLdb/cursors.py", line 173, in execute
File "build/bdist.macosx-10.6-universal/egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
_mysql_exceptions.OperationalError: (1050, "Table 'orders_proof_approved_associations' already exists")

Field definition:

proof_storage = FileSystemStorage(location=settings.FILE_UPLOAD_ROOT)

class Proof(mixins.ModifiedDates):
"""
Each Order eventually has a Proof or multiple rounds of Proofs. Required are a proof file and
a Record Set file containing the records used for the proof.
"""
def get_upload_path(instance, filename):
    proof_count = int(Proof.objects.filter(order=instance.order).count()) + 1

    destination_path = os.path.join(instance.order.ATTACHMENTS_RELATIVE_ROOT, 'proofs')

    return os.path.join(destination_path, '%02d_%s' % (proof_count, filename))

file = models.FileField(storage=proof_storage, upload_to=get_upload_path)
approved = models.BooleanField(default=0)
order = models.ForeignKey(Order)
record_set_file = models.FileField(storage=proof_storage, upload_to=get_upload_path)
approved_associations = models.ManyToManyField(Association)

Everything works fine when I remove the field, and the table is no where in sight.

Any thoughts as to why this would happen?

A: 

You can always pass the db_table option to a ManyToManyField to step around the default table name created/used by Django. See the documentation here.

However, you should not be seeing an error like this. If you could post your models code, we may be able to help better.

Rishabh Manocha
Tried it with the `db_table` arg, but same problem. The error message reads with the new table name, but that's the only difference. Will post the model code above.
Derek Reynolds
A: 

Was trying too hard to get django to do what I wanted.

I had two apps with a common name. Obviously a big no-no, but I had them organized in to subapps subapp1.appname and subapp2.appname. Anyway when it comes down to it Django only cares about the appname*, and when I ran syncdb it came across both apps in my INSTALLED_APPS setting and tried to install the m2m model twice. Anyway, solved by renaming one of the apps (funny enough to a more well suited name).

* In Django 1.2 there is better support for `app_labels` 
  which can be used instead of the app name when referencing.
Derek Reynolds