本文介绍了如何回滚,重置或删除Ecto测试数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,mix.test会清除测试数据库,但无法正常工作.

Usually mix.test cleans the test database, but it is not working.

可能是因为我正在尝试制作users模式,但是不想使用我所做的事情,所以我放弃了它.然后,我重新开始,为用户创建了一个与第一个不同的新架构.

It may be because I was playing around with making a users schema, but didn't want to use what I made so I got rid of it. I then started over and made a new schema for users which was different from the first.

当我尝试再次运行混合测试时,出现一个错误,即某些字段不存在,而新模式本应存在该字段.

When I tried to run mix test again, there was an error that some fields did not exist which should have been there with the new schema.

推荐答案

您可以使用MIX_ENV=test,后跟mix do ecto.dropmix ecto.resetmix ecto.rollback之类的命令来访问测试数据库.

You can access the test database by using MIX_ENV=test followed by a command such as mix do ecto.drop, mix ecto.reset or mix ecto.rollback.

在这种情况下,我使用了:

In this particular case, I used:

MIX_ENV=test mix ecto.reset


如果您的应用程序具有多个存储库(DB),则需要指定一个特定的存储库以避免将操作应用于所有存储库.例如


If your application has multiple repos (DBs), you'll want to specify a specific repo to avoid applying the operation to all repos. For example

mix ecto.drop --repo Order.Repo

要了解有关Ecto任务的更多信息,请使用mix help <task>

To find out more about an Ecto task, use mix help <task>

这篇关于如何回滚,重置或删除Ecto测试数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 08:37