6

I am following a tutorial and below is the code:

var Sequelize = require('sequelize')
var sequelize = new Sequelize('basic-mysql-database.mysql', 'root', 'password', {
    'dialect': 'mysql',
    'host': "localhost",
    "port": "3306"
});

var Todo = sequelize.define('todo', {
    description: {
        type: Sequelize.STRING
    },
    completed: {
        type: Sequelize.BOOLEAN

    }
})

sequelize.sync().then(function(){
    console.log('Everything is synced')

    Todo.create({
        description: 'Walking my dog',
        completed: false
    }).then(function (todo){
        console.log('Finished!')
        console.log(todo)
    })
});

I have installed MySQL. When I go into Settings > MySQL and it says MySQL Server instance is running

When I run node testDB.js I get the following error:

Unhandled rejection SequelizeConnectionError: ER_BAD_DB_ERROR: Unknown database 'basic-mysql-database.mysql'
    at Handshake._callback (/Users/Kausi/Documents/Development/todo-api/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:63:20)
    at Handshake.Sequence.end (/Users/Kausi/Documents/Development/todo-api/node_modules/mysql/lib/protocol/sequences/Sequence.js:85:24)
    at Handshake.ErrorPacket (/Users/Kausi/Documents/Development/todo-api/node_modules/mysql/lib/protocol/sequences/Handshake.js:105:8)
    at Protocol._parsePacket (/Users/Kausi/Documents/Development/todo-api/node_modules/mysql/lib/protocol/Protocol.js:280:23)
    at Parser.write (/Users/Kausi/Documents/Development/todo-api/node_modules/mysql/lib/protocol/Parser.js:74:12)
    at Protocol.write (/Users/Kausi/Documents/Development/todo-api/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/Users/Kausi/Documents/Development/todo-api/node_modules/mysql/lib/Connection.js:109:28)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:153:18)
    at Socket.Readable.push (_stream_readable.js:111:10)
    at TCP.onread (net.js:536:20)

I have never created any schema/table. I do have MySQL Workbench that I can create the schema and 'Todo' table with; however, I was under the impression that Sequelize does this on the fly? What am I doing wrong?

1
  • 2
    I don't think sequelize can make a database for you. It will only make a tables for you. Create that database first then just let the sequlizer create your table (just create your database) Commented Sep 20, 2016 at 1:30

2 Answers 2

8

There is a tiny little line in the setup that says:

The credentials for the respective database

Sync will create the tables for you, but it's not going to create the database.

Sign up to request clarification or add additional context in comments.

1 Comment

but what if we want to do this job with our app... like don't have to create our database manually just our will do this for us.. is their any way??
0

In mac I navigated to /Applications/MAMP/bin/phpMyAdmin/config.inc.php

And found that my username was "root" and password was also "root"

$cfg['Servers'][$i]['user']          = 'root';      
$cfg['Servers'][$i]['password']      = 'root';

https://stackoverflow.com/a/78066825/12228079

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.