gpt4 book ai didi

php - CakePHP烘焙所有未知问题

转载 作者:行者123 更新时间:2023-11-29 07:49:58 25 4
gpt4 key购买 nike

我是 Cake php 的新手。我在使用烘焙时遇到问题

我使用用户表设置了迁移

public $migration = array(
'up' => array(
'create_table' => array(
'users' => array(
'user_id' => array('type' => 'integer', 'null' => false, 'key' => 'primary'),
'username' => array('type' => 'string', 'null' => false, 'length' => 250),
'password' => array('type' => 'text', 'null' => false),
'created' => array('type' => 'string', 'null' => false, 'length' => 14),
'modified' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 14),
'indexes' => array(
'PRIMARY' => array('column' => 'user_id', 'unique' => 1)
)
)
)
),
'down' => array(
'drop_table' => array(
'users'
)
)
);

并将此文件迁移到数据库上,然后我尝试执行命令“蛋糕烘焙全部”问题是 User 使用 ownTo 和 hasMany 引用了自身这是默认使用烘焙吗?

class User extends AppModel {

/**
* Validation rules
*
* @var array
*/
public $validate = array(
'user_id' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'username' => array(
'notEmpty' => array(
'rule' => array('notEmpty'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'date_created' => array(
'notEmpty' => array(
'rule' => array('notEmpty'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
);

//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);

/**
* hasMany associations
*
* @var array
*/
public $hasMany = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);

}

我在这里缺少什么吗?我应该保留它并手动修改它还是有一个我错过的配置。

最佳答案

有三个简单的解决方案,正如最后一个答案所述,蛋糕烘焙都是遵循默认的蛋糕约定,并通过表中的 user_id 创建关联

  1. 将数据库字段从 user_id 重命名为 id,然后再次运行 shell。

  2. 运行蛋糕烘焙并手动选择模型并使用 shell 助手手动配置数据库关联

  3. 手动删除模型中的关联以及 Controller 和 View 中的引用。

关于php - CakePHP烘焙所有未知问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26739981/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com