1
我是新的cakephp,並有問題。我在mysql中創建了2個表格 我試圖創建的關係是'category_products'有許多'產品'。幫助CakePHP:我不能烤
CREATE TABLE category_products (
id int NOT NULL PRIMARY KEY,
name varchar(30) NOT NULL
) ENGINE=InnoDB;
CREATE TABLE products (
id int NOT NULL PRIMARY KEY,
name varchar(30) NOT NULL,
category_product_id int NOT NULL,
FOREIGN KEY (category_product_id) REFERENCES category_products(id)
) ENGINE=InnoDB;
當我烤「category_products」是所有罰款,但是當我在控制檯烤「產品」,我得到這個:
=============================================================
Possible Models based on your current database:
1. CategoryProduct
2. Product
Enter a number from the list above,type in the name of another model, or 'q' to exit
[q] > 2
Baking model class for Product...
Creating file /opt/lampp/htdocs/caketest/app/models/product.php
Wrote `/opt/lampp/htdocs/caketest/app/models/product.php`
Product Model was baked.
SimpleTest is not installed. Do you want to bake unit test files anyway? (y/n) [y] > n
**Error: Missing database table 'categories' for model 'Category'**
============================================================
Cakephp **doesn't create the view** and when i open the **model** for product.php and i see this at then end.
var $belongsTo = array(
'CategoryProduct' => array(
'className' => 'CategoryProduct',
'foreignKey' => 'category_product_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
var $hasAndBelongsToMany = array(
'Category' => array(
'className' => 'Category',
'joinTable' => 'category_products',
'foreignKey' => 'product_id',
'associationForeignKey' => 'category_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
我的問題是什麼我做錯了什麼???顯然cakephp認爲我試圖創建一個 關係HABTM。我正在使用cakephp 1.3.7
請幫助我。謝謝!