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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 21:38:46  来源:igfitidea点击:

OSError: [Errno 18] Invalid cross-device link

pythondjangodatabasesettingsbackend

提问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.renameonly works if source and destination are on the same file system. You should use shutil.moveinstead.

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

希望能帮助到你