2013-02-13 39 views
0

Sequelize for Express(node.js)出現問題。我試圖從MAMP Mac連接一個MySQL數據庫與Sequelize快遞,但它不工作,我不明白爲什麼,但我得到一個錯誤:使用MAMP進行Sequelize和MySQL,出現錯誤

也許我必須編輯MySQL配置文件的評論「MAMP_skip -networking_MAMP」但我沒有找到MAC MySQL的的conf文件...

我的代碼:

var Sequelize = require("sequelize"); 

var db = new Sequelize('express', 'root', 'root', { 
    host: '127.0.0.1', 
    port: '3306' 
}); 

var Project = db.define('Project', { 
    date: Sequelize.DATE, 
    title: Sequelize.STRING, 
    description: Sequelize.TEXT 
}); 

var project = Project.build({ 
    date: new Date(), 
    title: 'Mon premiéé projeétçç!!', 
    description: 'dsqlmdskq lkqskl ksqlmk lsmdqklm' 
}); 

project 
    .save(); 
+0

確認憑證是否正確,表已存在? – sdepold 2013-02-13 08:13:50

+0

我還沒有創建表格,但是如果我創建表格,是否必須添加主鍵? – tonymx227 2013-02-13 08:35:03

+0

只需在創建實例之前使用[sequelize.sync](http://sequelizejs.com/#models-sync)。 – sdepold 2013-02-13 08:47:11

回答

0

試試這個:

var Sequelize = require("sequelize"); 
var db = new Sequelize('express', 'root', 'root', { 
    host: '127.0.0.1', 
    port: '3306' 
}); 

var Project = db.define('Project', { 
    date: Sequelize.DATE, 
    title: Sequelize.STRING, 
    description: Sequelize.TEXT 
}); 

db.sync().success(function() { 
    var project = Project.build({ 
    date: new Date(), 
    title: 'Mon premiéé projeétçç!!', 
    description: 'dsqlmdskq lkqskl ksqlmk lsmdqklm' 
    }); 

    project.save(); 
}) 
1

嘗試使用端口8889而不是3306

相關問題