回滚学说数据:从装置插入失败时加载
我经常注意到,当模型的数据库插入失败时,之前加载的数据会继续保留在数据库中。因此,当您尝试再次加载相同的夹具文件时,会出现错误。
有什么方法可以使 DATA:LOAD 过程成为原子的,即对所有数据进行 GO 或 NO-GO,以便数据永远不会中途插入。
I have often noticed that when database insert for a model fails, data loaded previously continue to stay in the database. So when you try to load the same fixture file again, it gives an error.
Is there any way the DATA:LOAD process can be made ATOMIC, i.e. GO or NO-GO for all data, so that data is never inserted half-way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
希望这应该有效:
编写一个与 data:load 执行相同操作的任务,但将其包装在:
Hopefully that should work :
Write a task that do the same as data:load but wrap it in :
夹具用于加载初始数据,这意味着您应该能够
build --all --and-load
,或者换句话说,清除所有数据并重新加载夹具。不再需要更长的时间了。您的一种选择是将您的装置分成多个文件并单独加载它们。如果您首先需要通过脚本或 CSV 加载大量数据(即比几个固定装置更大的数据),我也会这样做。这样,如果您在其他地方遇到固定装置问题,则无需重做。
Fixtures are meant for loading initial data, which means that you should be able to
build --all --and-load
, or in other words, clear all data and re-load fixtures. It doesn't take any longer.One option you have is to break your fixtures into multiple files and load them individually. This is also what I'd do if you first need to load large amounts of data via a script or from a CSV (i.e. something bigger than just a few fixtures). This way you don't need to redo it if you had a fixtures problem somewhere else.