如何回滚,重置或删除Ecto测试数据库?
收藏

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

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.

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

最佳答案

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.

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

MIX_ENV=test mix ecto.reset

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

mix ecto.drop --repo Order.Repo

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

    公众号
    关注公众号订阅更多技术干货!