使用django迁移操作数据

Growing, successful applications are a lovely problem to have. As a product develops, it tends to accumulate complications the way your weekend cake project accumulates layers of frosting. Thankfully Django, my favorite batteries-included framework, handles complexity pretty well.

不断增长的成功应用程序是一个可爱的问题。 随着产品的发展,它往往会像周末蛋糕项目中积聚的糖霜一样,积聚复杂的东西。 值得庆幸的是,Django是我最喜欢的包含电池的框架,可以很好地处理复杂性。

Django models help humans work with data in a way that makes sense to our brains, and the framework offers plenty of classes you can inherit to help you rapidly develop a robust application from scratch. As for developing on existing Django applications, there’s a feature for that, too. In this article, we’ll cover how to use Django migrations to update your existing models and database.

Django模型帮助人们以对我们大脑有意义的方式处理数据,并且该框架提供了许多可以继承的类,以帮助您从头开始快速开发健壮的应用程序。 至于在现有Django应用程序上进行开发,也有一个功能。 在本文中,我们将介绍如何使用Django迁移来更新现有模型和数据库。

什么是内幕? (What’s Under the Hood?)

Django migrations are Python files that help you add and change things in your database tables to reflect changes in your Django models. To understand how Django migrations help you work with data, it may be helpful to understand the underlying structures we’re working with.

Django迁移是Python文件,可帮助您添加和更改数据库表中的内容以反映Django模型中的更改。 要了解Django迁移如何帮助您处理数据,了解我们正在使用的基础结构可能会有所帮助。

什么是数据库表? (What’s a database table?)

If you’ve laid eyes on a spreadsheet before, you’re already most of the way to understanding a database table. In a relational database — for example, a PostgreSQL database — you can expect to see data organized into columns and rows. A relational database table may have a set number of columns and any number of rows.

如果您以前曾关注过电子表格,那么您已经是理解数据库表的大部分方法。 在关系数据库(例如PostgreSQL数据库)中,可以期望看到按列和行组织的数据。 关系数据库表可以具有固定数量的列和任意数量的行。

In Django, each model is its own table. For example, here’s a Django model:

在Django中,每个模型都是其自己的表。 例如,这是Django模型:

from django.db import models
class Lunch(models.Model):
left_side = models.CharField(max_length=100, null=True)
center = models.CharField(max_length=100, null=True)
right_side = models.CharField(max_length=100, null=True)

Each field is a column, and each row is a Django object instance of that model. Here’s a representation of a database table for the Django model, Lunch, above. In the database, its nam

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值