sequelize / cli

The Sequelize CLI
MIT License
2.53k stars 526 forks source link

postgres tables created in migration cannot be accessed #588

Closed m2sillanpaa closed 4 years ago

m2sillanpaa commented 6 years ago

What you are doing?

I'm having problems creating models with sequelizer. Or more accurately I can create models and migrate them, but I cannot access, modify or delete them via psql.

I'm creating the model like this:

sequelize model:generate --name Device --attributes pid:string ip:string

output:

Sequelize CLI [Node: 4.6.1, CLI: 3.0.0, ORM: 4.22.6]

WARNING: This version of Sequelize CLI is not fully compatible with
Sequelize v4. https://github.com/sequelize/cli#sequelize-support

New model was created at
/home/matti/workspace/db_demo/server/models/device.js . New migration
was created at
/home/matti/workspace/db_demo/server/migrations/20171114134820-Device.js
.

migrating like this:

$ sequelize db:migrate

Sequelize CLI [Node: 4.6.1, CLI: 3.0.0, ORM: 4.22.6]

WARNING: This version of Sequelize CLI is not fully compatible with
Sequelize v4. https://github.com/sequelize/cli#sequelize-support

Loaded configuration file "server/config/config.json". Using
environment "development". sequelize deprecated String based operators
are now deprecated. Please use Symbol based operators for better
security, read more at
http://docs.sequelizejs.com/manual/tutorial/querying.html#operators
node_modules/sequelize/lib/sequelize.js:236:13
== 20171114134820-create-device: migrating =======
== 20171114134820-create-device: migrated (0.044s)

after this I can see the tables in pqsl.

my user credentials (using it as matti):

                                List of roles  
   Role name |                         Attributes                         | Member of 
  -----------+------------------------------------------------------------+-----------  
   matti     | Superuser, Create DB                                       | {}  
   postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

I'm working in Ubuntu 16.04.

I've reverted the migration and dropped the db just to be certain. But it didn't have any effect. Nor did restarting the postgres.

I can create, list and delete the db:ses as user "matti" from psql. But not the ones generated by the sequelizer.

migration file:

'use strict';
module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable('Devices', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      pid: {
        type: Sequelize.STRING
      },
      ip: {
        type: Sequelize.STRING
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE
      }
    });
  },
  down: (queryInterface, Sequelize) => {
    return queryInterface.dropTable('Devices');
  }
};

What do you expect to happen?

Working tables.

What is actually happening?

 device-dev=# \d
           List of relations  
 Schema |      Name      |   Type   | Owner 
--------+----------------+----------+-------  
 public | Devices        | table    | matti  
 public | Devices_id_seq | sequence | matti  
 public | SequelizeMeta  | table    | matti

However I cannot list the table:

device-dev=# \d Devices 
Did not find any relation named "Devices".

used versions: Sequelize: Sequelize CLI [Node: 4.6.1, CLI: 3.0.0, ORM: 4.22.6] postgres: psql (PostgreSQL) 10.1 nodejs: v4.6.1 npm: 2.15.9

sameekhan commented 6 years ago

Same problem :/

mortensenm1205 commented 6 years ago

Still no fix on this? I'm also running into the same issue

leemartin commented 6 years ago

Running into this issue as well. Migration runs fine but no tables seem to actually be created. :-( It took me a while to even notice this was happening because sync() was fixing things.

leemartin commented 6 years ago

Apparently my database wasn't connecting in development using the "use_env_variable" method. However, I wasn't receiving any errors.

Using this method...

development: {
    username: null,
    password: null,
    database: DATABASE_NAME,
    host: HOST,
    dialect: "postgres"
  }

fixed the issue. Migrations are running fine now.

tomorekoya commented 6 years ago

Check out this StackOverflow post, especially the comment made by 'a_horse_with_no_name': https://stackoverflow.com/questions/47288265/sequelizer-generated-postgres-tables-cannot-be-accessed

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.