所以我创建了一个新的Sails.js项目,然后运行
$ sails generate api user
如建议的加载页面。但是现在当我用服务器启动服务器时,sails lift
出现错误:
sails lift
info: Starting app...
-----------------------------------------------------------------
Excuse my interruption, but it looks like this app
does not have a project-wide "migrate" setting configured yet.
(perhaps this is the first time you're lifting it with models?)
In short, this setting controls whether/how Sails will attempt to automatically
rebuild the tables/collections/sets/etc. in your database schema.
You can read more about the "migrate" setting here:
http://sailsjs.org/#/documentation/concepts/ORM/model-settings.html?q=migrate
In a production environment (NODE_ENV==="production") Sails always uses
migrate:"safe" to protect inadvertent deletion of your data.
However during development, you have a few other options for convenience:
1. safe - never auto-migrate my database(s). I will do it myself (by hand)
2. alter - auto-migrate, but attempt to keep my existing data (experimental)
3. drop - wipe/drop ALL my data and rebuild models every time I lift Sails
What would you like Sails to do?
info: To skip this prompt in the future, set `sails.config.models.migrate`.
info: (conventionally, this is done in `config/models.js`)
我必须要运行帆迁移命令吗?我知道我会做类似的事情rake db:migrate
。生成命令后,帆中的程序是什么?
这不是错误,只是告诉您没有指定默认的迁移策略。
刚开 config/models.js
并取消注释上面所说的迁移行。
就像“弹出窗口”告诉您的信息一样,您可以选择
Drop将删除您的所有表并重新创建它们,这对一个新项目很有用,并且您想一直播种新的虚拟数据。
Alter会尝试保留您的数据,但是如果您在模型中这样做,则会对表进行更改。如果Sails无法保留数据,则将其删除。
顾名思义,安全是最安全的。它将对您的表无济于事。
如果要对不同的表采取不同的操作,则可以直接在模型中指定相同的选项,这些选项将仅覆盖该模型的默认设置。
因此,假设您有一个User
模型并希望保留该数据,但每次都希望重新创建所有其他模型sails lift
,则应添加
migrate: 'safe'
直接添加到模型中,并drop
用作默认策略。
我alter
个人喜欢,但这可能会引起人们的兴趣。
您不需要做其他任何事情。如果存在模型,并且将迁移设置为drop
或alter
,则将在sails lift
运行时进行迁移。
您可以在此处阅读有关模型设置的更多信息
作为旁注,您可以通过设置
log: 'verbose'
在您的config / env / development.js文件中:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句