Ecto 中 Migration 与 Schema 的区别

前端之家收集整理的这篇文章主要介绍了Ecto 中 Migration 与 Schema 的区别前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我们先来看一下 Ecto 文档中对 Migration 与 Schema 的描述:

Migration

Migrations are used to modify your database schema over time.

可以看出 Migration 是用来修改数据库的 schema 的,这里的 schema 或许与我们之后的所指不同.

Schema

Defines a schema.

An Ecto schema is used to map any data source into an Elixir struct. One of such use cases is to map data coming from a repository,usually a table,into Elixir structs.

或许我们可以这样理解,Database Schema 农场里原本的仓库,Migration 的作用是用不同的仓库来养鸡养牛,Ecto Schema 的作用是把这些动物做成吃的.

猜你在找的程序笔记相关文章