Posts

Showing posts with the label MySQL

shop_platform - 部署到 GCP (2)

Image
監聽 80 port(後來發現其實不需要) 試著在 80 port 上開啟伺服器,但是失敗了 flora@*******:~/shop_platform$ pipenv run gunicorn "app:create_app()" Loading .env environment variables... [2021-10-28 13:38:45 +0000] [22652] [INFO] Starting gunicorn 20.1.0 [2021-10-28 13:38:45 +0000] [22652] [ERROR] Retrying in 1 second. [2021-10-28 13:38:46 +0000] [22652] [ERROR] Retrying in 1 second. [2021-10-28 13:38:47 +0000] [22652] [ERROR] Retrying in 1 second. [2021-10-28 13:38:48 +0000] [22652] [ERROR] Retrying in 1 second. [2021-10-28 13:38:49 +0000] [22652] [ERROR] Retrying in 1 second. [2021-10-28 13:38:50 +0000] [22652] [ERROR] Can't connect to ('0.0.0.0', 80) 換成別的 port 就沒問題 flora@*******:~/shop_platform$ pipenv run gunicorn --bind 0.0.0.0:5000 "app:create_app()" Loading .env environment variables... [2021-10-28 14:00:11 +0000] [22879] [INFO] Starting gunicorn 20.1.0 [2021-10-28 14:00:11 +0000] [22879] [INFO] Listening at: http://0.0.0.0:5000 (22879) [2021-10-28 14:00:11 +0000] [22879] [...

shop_platform - Composite Foreign Keys

想要達到的效果: 現有 order_item 這張表。現在要建立 rating table ,並且建立 order_item 和 rating 之間的 one-one relationship。但 order_item 的 primary key 是 composite primary key,同時有兩個 column 都是 primary key。不知道要怎麼在 rating 建立外鍵。 order_item 的程式碼: from app import db from datetime import datetime class OrderItem(db.Model): __tablename__ = 'order_item' order_id = db.Column(db.Integer, db.ForeignKey('order.id'), primary_key=True) product_id = db.Column(db.Integer, db.ForeignKey('product.id'), primary_key=True) price = db.Column(db.Integer, nullable=False) quantity = db.Column(db.Integer, nullable=False) insert_time = db.Column(db.DateTime, nullable=False, default=datetime.now) update_time = db.Column(db.DateTime, onupdate=datetime.now, nullable=False, default=datetime.now) order = db.relationship('Order', back_populates='products') product = db.relationship('Product', back_populates='orders') 參考資料 用「sqlalchemy foreign...

MySQL 初始化小抄(使用環境:node.js)

安裝 MySQL 和 Workbrench 在 Workbrench 建立 DATABASE CREATE DATABASE 資料庫名稱; 安裝套件 npm install mysql2 sequelize sequelize-cli 執行初始化腳本 npx sequelize init 初始化腳本會建立四個東西 config/config.json 修改資料庫名稱及登入密碼。 (註:operatorsAliases 在 Sequelize v5 後已棄用) models/index.js migrations seeders 設定 model 和 seed: 官方文件