Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAmy Namdar
13,616 PointsData type that prevents empty strings when creating a model instance?
I'm stuck on this question. Sequelize.STRING is obviously not sufficient, but adding on allowNull: false, validate with notNull/notEmpty is not working either. Feel as though I've tried everything. Help, please?
The question is: Complete the code below by adding the data type that prevents empty strings when creating a model instance:
Car.init({
Make: {
type: Sequelize.<FILL IN ANSWER>
},
}, { sequelize });
2 Answers
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 PointsHi Amy,
I guess I understand why you feel that STRING would not (or should not) be sufficient, but Sequelize.STRING is indeed the correct answer.
Yes, you would need to add validation. But the Datatype that would make that validation relevant to a string is STRING. Adding a notEmpty validation to a Sequelize.BOOLEAN datatype (for example) would do nothing with regards to strings (assuming thatβs a valid validator for the BOOLEAN datatype). So even though Sequelize.STRING isnβt enough code to prevent your user from inputting an empty string, it is the only Datatype that prevents empty strings as itβs the only one that requires a string.
I hope that makes sense.
Amy Namdar
13,616 PointsThank you! It worked. I was so certain that I had tried that. Appreciate your answer!