Skip to main content
 首页 » 编程设计

python之两勺 django 1.8 的 ch2.1.1 是什么意思

2024年10月24日38lovecherry

ch 2.1.1 的标题是您无法在本地检查生产数据的精确副本

内容如下:

When your production database is different from your local development database, you can’t grab an exact copy of your production database to examine data locally.

Sure, you can generate a SQL dump from production and import it into your local database, but that doesn’t mean that you have an exact copy after the export and import.

什么意思?

请您参考如下方法:

假设您正在运行 Postgres或 MySQL在生产中,和sqlite开发中。 Django ORM 使您能够编写适用于三种数据库的 python 代码(在大多数情况下),但每个数据库支持不同的功能,这使得它们彼此之间略有不兼容(尽管它们都是 RDBMS 并使用 SQL)。

如果您从您的生产 Postgres 或 MySQL 数据库中获取数据库转储并尝试在 sqlite 上执行它,它可能会加载所有数据,但在幕后会有很多差异(列类型、外键、索引、任何非标准扩展,例如 JSON in Postgres、如何计划和执行查询、编码、整理、存储引擎等)。即使是同一数据库软件的不同版本,其工作方式也可能不同。

比如sqlite只有five data types : null, integer, real, text, blob.将此与 MySQL 中的数十种类型进行比较和 Postgres .

我没有这本书,但我猜他们在说:如果您想完全确定您在开发中编写的代码在生产中也能正常工作,那么您应该使用相同的代码两种环境中的数据库软件。