我是Postgres和Sequelize的新手,我已经成功连接到数据库,试图在数据库中创建一个表格,这是一个错误,表格名称不存在
fetching https://www.recode.net/ (queue crawl delay=5000ms)
Thread FetcherThread has no more work available
-finishing thread FetcherThread, activeThreads=1
Using queue mode : byHost
robots.txt whitelist not configured.
Thread FetcherThread has no more work available
-finishing thread FetcherThread, activeThreads=1
Using queue mode : byHost
Using queue mode : byHost
Thread FetcherThread has no more work available
-finishing thread FetcherThread, activeThreads=1
Using queue mode : byHost
Thread FetcherThread has no more work available
-finishing thread FetcherThread, activeThreads=1
Using queue mode : byHost
..........................
..........................
Fetcher: throughput threshold: -1
Fetcher: throughput threshold retries: 5
fetcher.maxNum.threads can't be < than 50 : using 50 instead
Thread FetcherThread has no more work available
-finishing thread FetcherThread, activeThreads=1
Thread FetcherThread has no more work available
-finishing thread FetcherThread, activeThreads=3
Thread FetcherThread has no more work available
Thread FetcherThread has no more work available
-finishing thread FetcherThread, activeThreads=2
-finishing thread FetcherThread, activeThreads=1
-activeThreads=1, spinWaiting=0, fetchQueues.totalSize=0, fetchQueues.getQueueCount=1
fetch of https://www.recode.net/ failed with: Http code=403, url=https://www.recode.net/
Thread FetcherThread has no more work available
-finishing thread FetcherThread, activeThreads=0
-activeThreads=0, spinWaiting=0, fetchQueues.totalSize=0, fetchQueues.getQueueCount=0
-activeThreads=0
Fetcher: finished at 2017-09-21 15:39:07, elapsed: 00:00:03
哪里出错了?它说错误:关系&#34;喜欢&#34;不存在。任何形式的帮助表示赞赏
答案 0 :(得分:13)
Sequelize仅通过sync
或迁移创建表格。您的模型News
有一个sync
方法,调用后会执行以下操作之一
如果没有参数调用,它将创建表(如果它不存在)
如果调用此News.sync({ force: true })
,它将删除当前表(如果存在并创建一个新表)。
如果调用此News.sync({ alter: true })
,它将添加模型中尚未出现的任何新字段(这是v4功能)。
这些技术在快速原型设计时非常有用,但最佳解决方案是使用迁移。迁移允许您跟踪开发,不同git分支和生产中数据库的更改。它是迄今为止最好的解决方案,但确实需要少量的前期成本和买入费用。
如果你正在开发一个黑客马拉松风格的项目,我会选择{alter: true}
,但是如果你正在构建一些你将要工作一段时间的东西,那么一定要了解migrations API