Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将数据保存在django模型don';事实上,我没有存钱_Django_Orm_Save - Fatal编程技术网

将数据保存在django模型don';事实上,我没有存钱

将数据保存在django模型don';事实上,我没有存钱,django,orm,save,Django,Orm,Save,我该如何理解这一点?这是怎么发生的? 进入django shell: >>> from customauth.models import Profile >>> p = Profile.objects.get(user_id=1) >>> p.status u'34566' >>> p.status = 'qwerty' >>> p.status 'qwerty' >>> p.save()

我该如何理解这一点?这是怎么发生的? 进入django shell:

>>> from customauth.models import Profile
>>> p = Profile.objects.get(user_id=1)
>>> p.status
u'34566'
>>> p.status = 'qwerty'
>>> p.status
'qwerty'
>>> p.save()
>>> p.status
'qwerty'
>>> p = Profile.objects.get(user_id=1)
>>> p.status
u'qwerty'
>>> 
退出并再次进入django shell:

>>> from customauth.models import Profile
>>> p = Profile.objects.get(user_id=1)
>>> p.status
u'qwerty'
>>> 
一切似乎都很好。但是现在去地狱吧:

mysql> select user_id, status from customauth_profile where user_id=1;
+---------+--------+
| user_id | status |
+---------+--------+
|       1 | 34566  |

如果关闭shell后数据仍然存在,则数据不太可能保存到数据库中。能否检查settings.py并确保保存到正确的mysql数据库?

shell会话是一个数据库事务。由于事务隔离,外部连接看不到更改。您需要提交事务-最简单的方法是退出shell并重新启动


在普通请求中,Django会在请求结束时自动提交,因此这种行为不是问题。

问题出在缓存模块中。奇怪的是,并没有缓存中间件被插入,缓存并没有用于保存方法。
使用的是
django.core.cache.backends.locmem.LocMemCache
模块,可能是它坏了或者有一些奇怪的功能,我不知道。将尝试memcached模块,它应该(我希望)在不关闭站点缓存的情况下修复问题。

我也遇到了同样的问题,我正在使用Django和Mongo。。。在
object.save()之后,数据没有被持久化。。。他们,我用它来解决:

object.save_base(force_update=True)

现在正在为我工作,希望能有所帮助。

设置中只有一个数据库。当我试图解决这个问题时,它在两个小时内保存了两次。但是只有两次,我不知道为什么。。。每次成功保存后,我都会再次尝试,代码没有更改,但再次失败。这可能很重要:我正在使用django.contrib.gis.db.backends.mysql后端作为数据库(需要djagno_cities应用程序)和托管在Amazon上的项目,该项目的GPL mysql RDS作为数据库。我问题中的第二个代码块是重新启动shell会话。我做了更改,退出shell并重新启动它。我使用sqlite后端,但在django shell中也发生了这种情况。但不需要强制更新=True。超级奇怪,因为
.save()
以前从未让我失望过。。。谢谢你救了我的命:)