简体   繁体   English

Doctrine如何处理对数据库架构的更改?

[英]How does Doctrine handle changes to the database schema?

In brief, what happens when you add a column to a table? 简而言之,当您向表中添加列时会发生什么? What happens when you remove one? 删除一个时会发生什么?

In more details, suppose you have the following: 更详细地,假设您具有以下条件:

class User extends Doctrine_Record
{
    public function setTableDefinition()
    {
        $this->hasColumn('username', 'string', 255);
        $this->hasColumn('password', 'string', 255);
    }
}

What happens when you add the following line to the setTableDefinition function? 将以下行添加到setTableDefinition函数中会发生什么?

$this->hasColumn('firstname', 'string', 255);

What happens when you delete the following line from the setTableDefinition function? 从setTableDefinition函数中删除以下行会发生什么?

$this->hasColumn('password', 'string', 255);

You'd want to have a look at Doctrine migrations that allows you to 您想看看Doctrine迁移 ,它使您能够

The Doctrine migration package allows you to easily update your production databases through a nice programmatic interface. 通过Doctrine迁移软件包,您可以通过漂亮的编程界面轻松地更新生产数据库。 The changes are done in a way so that your database is versioned and you can walk backwards and forwards through the database versions. 所做的更改以某种方式进行,以便对数据库进行版本控制,并且可以在数据库版本之间来回移动。

That will allow you to perform changes to your database without screwing up your data. 这样一来,您无需更改数据即可对数据库进行更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM