Python OSError: [Errno 18] 无效的跨设备链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42392600/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OSError: [Errno 18] Invalid cross-device link
提问by mark
I'm working with django 1.6.5 and python 2.7. I have import feature in my app and I get error:
我正在使用 django 1.6.5 和 python 2.7。我的应用程序中有导入功能,但出现错误:
OSError: [Errno 18] Invalid cross-device link
I have problem with this part of code:
我对这部分代码有问题:
os.rename(db_temp, settings.DATABASES['bookmat']['NAME'])
code in settings:
设置中的代码:
'bookmat': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/my_projects/book/db/bookmat.sqlite3',
},
回答by butesa
os.rename
only works if source and destination are on the same file system. You should use shutil.move
instead.
os.rename
仅当源和目标位于同一文件系统上时才有效。你应该shutil.move
改用。
回答by Tiago Almeida
I think rename only works when the source and target names are on the same file system. You probably have different mounts. Otherwise you get that error. You can implement the same effect with a copy and a delete.
我认为重命名仅在源名称和目标名称位于同一文件系统上时才有效。你可能有不同的坐骑。否则你会得到那个错误。您可以通过复制和删除来实现相同的效果。
Hope it helps
希望能帮助到你