1

I run

$ sequelize db:migrate, 

but I get this result, with an ERROR

Loaded Configuration file "db\config\config.json".
Using environment "development".
==20190927081141-add-email-to-contacts: migrating =======

ERROR: Cannot read property 'toString' of undefined

This is my current config.json file, but I don't have any toString property in it.

//config.json

{
  "development": {
    "port":5432,
    "username": "postgres",
    "password": null,
    "database": "address-bloc-dev",
    "host": "127.0.0.1",
    "dialect": "postgres",
    "logging":false
  },
  "test": {
    "username": "postgres",
    "password": null,
    "database": "address-bloc-test",
    "host": "127.0.0.1",
    "dialect": "postgres",
    "logging": false
  }
}

Here is also the add email to contacts.js file

'use strict';
module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.addColumn('Contacts', 'email',
     {
      email: {
          type: Sequelize.STRING,
      }
    });
  },
  down: (queryInterface, Sequelize) => {
    return queryInterface.removeColumn('Contacts', 'email');
  }
};

What am I doing wrong? I'm struggling in figuring it out.

Thank you

Federico

4 Answers 4

3

Had a similar issue with changeColumn(), ensure that that you completely define the new data type of the column that you intend to change.

Sequelize Docs This method changes the meta data of an attribute. It is possible to change the default value, allowance of null or the data type. Please make sure, that you are completely describing the new data type.

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

1 Comment

@Smartninggs, When I am setting allowNull:false it is throwing the same error! I have only this allowNull propery needs to set! So Do I need to put other things as well like default value, datatype?
1

This error is not coming from the config.json file, but rather the 20190927081141-add-email-to-contacts. The error is from there.

EDIT:

What you are doing wrong is how you are setting the type of the email field.

You should do:

'use strict';
module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.addColumn('Contacts', 'email',
     {
        type: Sequelize.STRING,
     });
  },
  down: (queryInterface, Sequelize) => {
    return queryInterface.removeColumn('Contacts', 'email');
  }
};

1 Comment

thank you, I have just included it into the question
1

I have this error and the solution was to modify just a word.

the place of the error

  id:{
      ype: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV1,
      primaryKey: true,
      allowNull: false,
    }

the solution was

 id:{
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV1,
      primaryKey: true,
      allowNull: false,
    }

just added the missing letter

Comments

0

follow steps below:

  1. install sequelize-cli: npm install -g sequelize-cli

  2. install sequelize: npm install --save sequelize

  3. install mysql2: npm install --save mysql2

  4. initialize sequelize: sequelize init

  5. delete the migration and seeder directory automatically generated

  6. create a model (e.g user model):

     module.exports = (sequelize, DataTypes) => {
        const User = sequelize.define('users', {
          name: {
                 type: Datatype.STRING,
                 allowNull: false,
                },
    
          userRole: {
                 type: Datatype.INTEGER,
                 allowNull: false,
                },
      });
    return User;
    

    }

  7. Add db.sequelize.sync({ force: true, logging: console.log }); to your server.js after db has been defined.

  8. run your server

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.