Guest User

Untitled

a guest
Aug 18th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. var Sequelize = require("sequelize").Sequelize;
  2.  
  3. var sequelize = new Sequelize('andrewfox_main', 'andrewfox_dev', 'seurat', {
  4. host: "mysql.andrewfoxmusics.com"
  5. });
  6.  
  7.  
  8. User = sequelize.define('User', {
  9. name: { type: Sequelize.STRING, allowNull: false},
  10. email: { type: Sequelize.STRING, allowNull: false},
  11. password: { type: Sequelize.STRING, allowNull: false},
  12. isAdmin: { type: Sequelize.BOOLEAN, allowNull: false, default: false }
  13. });
  14.  
  15.  
  16. sequelize.sync(); // Syncs table changes if there are any. If the table doesn't exist, it creates it.
  17.  
  18.  
  19. gabe = new User({name:'Gabe',email:'gabe@advizo.com',password:null});
  20.  
  21. try{
  22. gabe.save(); // Won't work. password cannot be null.
  23. }
  24. catch(err){
  25. console.log(err.message); // THROWS 'The object is not valid! Invalid fields: email'
  26. }
  27.  
  28. gabe.password = 'test1234';
  29.  
  30.  
  31.  
  32. gabe.save(); // NO ERROR
Add Comment
Please, Sign In to add comment