question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sequelize Error: Table is not created yet

See original GitHub issue

I receive this error Error: Table is not created yet however it creates the table called Limiters fine.

import { RateLimiterMySQL } from "rate-limiter-flexible";
import { Handler, Request } from "express";
import { db } from "../../models";
import { config } from "../../config/";

class RateLimiterMiddleware extends RateLimiterMySQL {
  constructor(ready) {
    super(
      {
        storeClient: db.sequelize,
        dbName: config.mysql.database,
        points: 10,
        duration: 1,
      },
      ready,
    );
  }
  middleware: Handler = async (request: Request, response, next) => {
    try {
      await this.consume(request.ip);
      next();
    } catch (error) {
      response.sendStatus(429); // Too Many Requests
    }
  };
}

export { RateLimiterMiddleware };

I can see that the table has been created image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pete183commented, Apr 13, 2020

Ah I see - thank you so much for your help!

0reactions
animircommented, Apr 13, 2020

@pete183 ok, Promise should be resolved only when table is created/checked

const createApp = async () => {
  await sync();

  const app = express();
  return new Promise((resolve, reject) => {
    const ready = err => {
      if (err) {
        reject(err)
      } else {
        // db and table checked/created

        CreateRoutes(app);

        const apolloServer = new ApolloServer({
          typeDefs,
          resolvers,
          context: ({ req }: { req: Request }) => ({
            ...jwtController.createAuthScope(req.headers.authorization),
          }),
        });
        apolloServer.applyMiddleware({
          app,
        });
        // !!! you should resolve only when everything is ready
        resolve(app);
      }
    };

    app.use(new RateLimiterMiddleware(ready).middleware);
  })
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Sequelize sync and Node.js not create table
In my case i just import Model to app.js const sequelize = require("./src/Utils/database"); const User = require(".
Read more >
Model Basics
A model in Sequelize has a name. This name does not have to be the same name of the table it represents in...
Read more >
Associations
To create a One-To-One relationship, the hasOne and belongsTo associations are used together; ... CREATE TABLE IF NOT EXISTS "foos" (
Read more >
Model Instances
Model Instances · Creating an instance​. Although a model is a class, you should not create instances by using the new operator directly....
Read more >
Advanced M:N Associations
You probably noticed that the User_Profiles table does not have an id field ... The above will still create two columns userId and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found