2014-02-19 82 views
0

錯誤 我在一臺服務器上有一個工作站點。我決定把它搬到另一家公司。我用phpmyadmin導出數據庫並上傳到新服務器中。每次我嘗試導入數據庫我收到此錯誤:Contraint sql錯誤:#1005 - 無法創建表

SQL查詢:

-- 
-- Constraints for table `seller_cart` 
-- 
ALTER TABLE `seller_cart` 
    ADD CONSTRAINT `seller_cart_ibfk_1` 
    FOREIGN KEY (`subscription`) 
     REFERENCES `subscription` (`id`) , 
    ADD CONSTRAINT `seller_cart_ibfk_2` 
    FOREIGN KEY (`user`) 
     REFERENCES `users` (`user_id`) 
    ON DELETE CASCADE 
    ON UPDATE CASCADE , 
    ADD CONSTRAINT `seller_cart_ibfk_3` 
    FOREIGN KEY (`featured_item`) 
     REFERENCES `featured_item` (`item`) 
    ON DELETE CASCADE 
    ON UPDATE CASCADE ; 

MySQL表示:文件

#1005 - Can't create table 'project123.#sql-12050_1d' (errno: 150) (Details...) 

這裏的賣家購物車的結構:

-- 
-- Table structure for table `seller_cart` 
-- 

CREATE TABLE IF NOT EXISTS `seller_cart` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT, 
    `user` bigint(20) NOT NULL, 
    `subscription` bigint(20) DEFAULT NULL, 
    `description` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL, 
    `item_listings` text COLLATE utf8_unicode_ci, 
    `featured_item` bigint(20) DEFAULT NULL, 
    `quantity` int(2) NOT NULL, 
    `price` float NOT NULL, 
    PRIMARY KEY (`id`), 
    KEY `user` (`user`), 
    KEY `subscription` (`subscription`), 
    KEY `featured_item` (`featured_item`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; 

可能是什麼問題?我剛剛導出並導入了相同的數據庫。甚至在本地主機上也嘗試過同樣的問題。

回答

0

當您嘗試引用未索引的列時會引發此錯誤。

檢查

  1. 訂閱(ID)
  2. 用戶(USER_ID)
  3. featured_item(項目)

具有已定義的有效指標。如果沒有,請定義它們並運行您的ALTER ...聲明。

請參閱要:規則外鍵約束:

+0

結構: CREATE TABLE IF NOT EXISTS'seller_cart'( 'id' BIGINT(20)NOT NULL AUTO_INCREMENT, 'user' bigint(20)NOT NULL, 'subscription' bigint(20)DEFAULT NULL, 'description' varchar(200)C OLLATE utf8_unicode_ci DEFAULT NULL, 'item_listings'文本COLLATE utf8_unicode_ci, 'featured_item' BIGINT(20)DEFAULT NULL, 'quantity' INT(2)NOT NULL, 'price'浮NOT NULL, PRIMARY KEY('id' ), KEY'user'('user'), KEY'subscription'('subscription'), KEY'featured_item'('featured_item') )ENGINE = InnoDB DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci AUTO_INCREMENT = 1; –

+0

那麼,索引必須在父列上的父表中定義。 –

相關問題