Halil Han BADEM
Evet abi, son kodlarım bu şekilde ve alter koyunca da çalışıyorlar. Herhangi birini sync({ force:true })
yapınca hata veriyormuş.
const { DataTypes } = require("sequelize");
const sequelize = require("../data/db");
const Post = sequelize.sequelize.define("post", {
id:{
primaryKey: true,
type: DataTypes.INTEGER,
autoIncrement: true,
allowNull: false
},
u_id:{
type: DataTypes.INTEGER,
allowNull: false
},
visible:{
type: DataTypes.BOOLEAN,
default: true,
allowNull: false
},
writetext:{
type:DataTypes.TEXT,
allowNull: true
},
media:{
type:DataTypes.TEXT,
allowNull: true
}
})
try{
const sync = async create => {
await Post.sequelize.sync({alter:true});
const count = await Post.count();
if (!count) {
Post.bulkCreate([{
u_id: 1,
visible: true,
writetext: "Post-1",
media:"/public/gecici/post.jpg"
},
{
u_id: 2,
visible: true,
writetext: "Bizler, Fatih'in torunları, yakında putları devirip, Yine seni camiye çevireceğiz...",
media:"/public/gecici/ayasofya.jpeg"
}
])
}
};
sync();
}catch(err){console.log("Veritabanı oluşturulamadı:", err)}
module.exports = Post;