如何通过cakephp迁移在数据库表中添加字段? [英] How to add a field in database table by cakephp migration?

查看:87
本文介绍了如何通过cakephp迁移在数据库表中添加字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Cakephp版本3中非常陌生。在这里,我尝试使用迁移插件。我已经使用以下命令创建了一个表

I am very new in cakephp version 3. Here I am trying to use migration plugin. I have already created a table by using below command

=> cake bake migration CreateUsers name : string 

工作得很好,现在我试图在其中添加一个字段在这里,我写了

It's worked very fine, now I am trying to add a field in here so I have written

=> cake bake migration add age:int to Users 

这是行不通的。我如何通过使用must命令迁移来添加此字段?请您能帮我吗?

It's not working. How can I add this field by migration using shall command ?May you help me please ?

推荐答案

类似语法

add column:type to table

不存在,所以这就是为什么您看到自己所看到的。添加列的正确语法是

doesn't exist, so that's why you are seeing what you're seeing. The correct syntax for adding columns is

AddColumnNameToTableName column:type

其中 Add To之间的列名是可选的。

即您的命令应类似于

bin/cake bake migration AddAgeToUsers age:int 

请参阅

  • Cookbook > Migrations > Creating Migrations
  • https://github.com/cakephp/migrations

这篇关于如何通过cakephp迁移在数据库表中添加字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆