2010-03-30 47 views
0

當我將ModelToModelField包括到我的某個模型中時,會引發以下錯誤。SyncDB上的ManyToManyField「表存在」錯誤

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") 

字段的定義:當我刪除該字段

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) 

一切工作正常,並且該表是看不到的地方。

有關爲什麼會發生這種情況的任何想法?

回答

0

正在努力讓django去做我想做的事。

我有兩個具有通用名稱的應用程序。顯然是一個很大的禁忌,但我把他們組織到了subapps subapp1.appnamesubapp2.appname。無論如何,當它涉及到Django只關心appname *,並且當我運行syncdb時,它在我的INSTALLED_APPS設置中遇到了兩個應用程序,並試圖安裝兩次m2m模型。無論如何,通過重命名其中一個應用程序來解決(足夠有趣,以更好地適應名稱)。

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

您總是可以將db_table選項傳遞給ManyToManyField以跳過由Django創建/使用的默認表名稱。請參閱documentation here

但是,你不應該看到這樣的錯誤。如果您可以發佈您的模型代碼,我們可能會提供更好的幫助。

+0

用'db_table' arg試過了,但是同樣的問題。錯誤消息與新的表名讀取,但這是唯一的區別。將發佈上面的模型代碼。 – 2010-03-30 15:11:56