Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CakePHP烘焙所有未知问题_Php_Mysql_Cakephp - Fatal编程技术网

CakePHP烘焙所有未知问题

CakePHP烘焙所有未知问题,php,mysql,cakephp,Php,Mysql,Cakephp,我是新来的。 我在使用bake时遇到问题 我使用用户表设置了迁移 public $migration = array( 'up' => array( 'create_table' => array( 'users' => array( 'user_id' => array('type' => 'integer', 'null' => false, '

我是新来的。 我在使用bake时遇到问题

我使用用户表设置了迁移

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'
            )
        )
    );
在数据库上迁移这个文件,然后我尝试执行命令“蛋糕烘焙全部” 问题是用户用belongsTo和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' => ''
        )
    );

}
这里有我遗漏的东西吗? 我应该保留它并手动修改它,还是遗漏了一个配置。

这是正确的


使用
cake bake all
时,它会按照惯例自动向表中添加引用。当你的桌子指的是她自己时,他确定了“hasMany”和“belongsTo”关系。您应该删除不存在的链接或默认情况下生成的更改。参考资料:

有三种简单的解决方案,因为最后一个答案指出,cake bake all遵循默认的cake约定,并通过表中有一个用户id来创建关联

  • 将数据库字段从
    user\u id
    重命名为
    id
    ,然后再次运行shell

  • 运行
    cake bake
    并手动选择model,然后使用shell助手手动配置数据库关联

  • 手动删除模型中的关联以及控制器和视图中的引用