2017-05-31 114 views
0

我正嘗試使用django FileFiled的動態上載路徑。 這是我的模型:,Django遷移使用FileField與動態上載路徑失敗

Traceback (most recent call last): 
File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) 
File "/home/mb/.local/lib/python3.5/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line 
utility.execute() 
File "/home/mb/.local/lib/python3.5/site-packages/django/core/management/__init__.py", line 355, in execute 
self.fetch_command(subcommand).run_from_argv(self.argv) 
File "/home/mb/.local/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv 
self.execute(*args, **cmd_options) 
File "/home/mb/.local/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute 
output = self.handle(*args, **options) 
File "/home/mb/.local/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 83, in handle 
executor = MigrationExecutor(connection, self.migration_progress_callback) 
File "/home/mb/.local/lib/python3.5/site-packages/django/db/migrations/executor.py", line 20, in __init__ 
self.loader = MigrationLoader(self.connection) 
File "/home/mb/.local/lib/python3.5/site-packages/django/db/migrations/loader.py", line 52, in __init__ 
self.build_graph() 
File "/home/mb/.local/lib/python3.5/site-packages/django/db/migrations/loader.py", line 203, in build_graph 
self.load_disk() 
File "/home/mb/.local/lib/python3.5/site-packages/django/db/migrations/loader.py", line 114, in load_disk 
migration_module = import_module("%s.%s" % (module_name, migration_name)) 
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module 
return _bootstrap._gcd_import(name[level:], package, level) 
File "<frozen importlib._bootstrap>", line 986, in _gcd_import 
File "<frozen importlib._bootstrap>", line 969, in _find_and_load 
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked 
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked 
File "<frozen importlib._bootstrap_external>", line 665, in exec_module 
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed 
File "/media/sf_Websites/HM/trunk/assignments/models/migrations/0001_initial.py", line 11, in <module> 
class Migration(migrations.Migration): 
File "/media/sf_Websites/HM/trunk/assignments/models/migrations/0001_initial.py", line 23, in Migration 
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 
AttributeError: module 'models' has no attribute 'AutoField' 

如果不知道它爲什麼發生在我使用的是靜態的上傳路徑是:

def use_assignment_path(instance, filename): 
    return 'assignment/%s/%s' % (instance.name, filename) 


class Assignment(models.Model): 
    admin = models.ForeignKey(Admin) 
    name = models.CharField(max_length=50, unique=True) 
    lang = models.CharField(max_length=5, default='c', choices=(('c', 'c'), ('java', 'java'))) 
    pointsRecommended = models.IntegerField() 
    file0 = models.FileField(upload_to=use_assignment_path) 
    file1 = models.FileField(upload_to=use_assignment_path, default='', blank=True) 

當我嘗試遷移模型我得到這個錯誤工作得很好。

我已經閱讀了幾個類似的問題,但沒有什麼幫助,直到知道。

坦克你!

回答

0

看起來好像你的應用程序名稱modelsdjango.db.models衝突。嘗試重命名您的應用,刪除初始遷移,然後重新運行makemigrationsmigrate

+0

謝謝你的工作! – Max

0

刪除「/media/sf_Websites/HM/trunk/assignments/models/migrations/0001_initial.py」文件,然後再試一次

+0

試過它不起作用 – Max