CakePHP bake all unknown issue
我是Cake php的新手。
我在使用bake
时遇到问题
我使用用户表设置了迁移
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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' ) ) ); |
并在db上迁移此文件,然后我尝试执行命令" cake bake all"
问题是用户使用belongsTo和hasMany对其自身进行了引用
是使用bake的默认设置吗?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | 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的事实来创建关联
将数据库字段从
运行
手动配置数据库关联
没错。
使用