【问题标题】:ValueError: path is on mount 'C:', start on mount 'F:' while django migrations in windowsValueError: path is on mount 'C:', start on mount 'F:' while django migrations in windows
【发布时间】:2017-03-19 20:06:32
【问题描述】:

我正在尝试运行以下命令

python manage.py makemigrations

但是,得到错误

ValueError: path is on mount 'C:', start on mount 'F:'

可能是什么原因?

完整的回溯:-

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py",  line 367, in execute_from_command_line
utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 345, in execute
output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\django\core\management\commands\makemigrations.py", line 189, in handle
self.write_migration_files(changes)
File "C:\Python34\lib\site-packages\django\core\management\commands\makemigrations.py", line 207, in   write_migration_files
migration_string = os.path.relpath(writer.path)
File "C:\Python34\lib\ntpath.py", line 579, in relpath
raise ValueError(error)
ValueError: path is on mount 'C:', start on mount 'F:'

【问题讨论】:

    标签: django django-migrations


    【解决方案1】:

    发生错误是因为 Django 试图在 2 个目录之间查找相对路径,但它们不存在(因为它们位于不同的驱动器上)。这里提到了这个问题:https://bugs.python.org/issue7195。但是这个回复有助于理解问题:https://bugs.python.org/msg94780

    os.relpath 确实为您提供了两个目录之间的相对路径。

    您遇到的问题是,在 Windows 上,相对路径 如果两个目录位于不同的驱动器上,甚至不存在 (这正是错误消息所说的)。

    当我遇到此错误时,我正试图为位于 F: 驱动器上的我自己的应用程序创建一个迁移文件。运行:

    python.exe .\manage.py makemigrations
    

    让 Django 扫描每个更改。它为 djcelery 找到了一个变化。它位于我的 C: 驱动器上的虚拟环境中。

    为了解决这个问题,我只是在调用 makemigrations 时添加了应用名称:

    python.exe .\manage.py makemigrations <<app_name>>
    

    【讨论】:

      猜你喜欢
      • 2021-09-26
      • 2013-04-11
      • 2022-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-07
      • 1970-01-01
      • 2012-06-04
      相关资源
      最近更新 更多