{"id":42007,"date":"2023-08-07T01:08:00","date_gmt":"2024-02-20T05:47:39","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8flask-sqlalchemy%e5%92%8cpostgresql%e6%9d%a5%e5%88%9b%e5%bb%baweb%e6%9c%8d%e5%8a%a1%e3%80%82\/"},"modified":"2024-04-30T17:19:33","modified_gmt":"2024-04-30T09:19:33","slug":"%e4%bd%bf%e7%94%a8flask-sqlalchemy%e5%92%8cpostgresql%e6%9d%a5%e5%88%9b%e5%bb%baweb%e6%9c%8d%e5%8a%a1%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8flask-sqlalchemy%e5%92%8cpostgresql%e6%9d%a5%e5%88%9b%e5%bb%baweb%e6%9c%8d%e5%8a%a1%e3%80%82\/","title":{"rendered":"\u4f7f\u7528Flask-SQLAlchemy\u548cPostgreSQL\u6765\u521b\u5efaWeb\u670d\u52a1"},"content":{"rendered":"<h1>\u4f7f\u7528Flask-SQLAlchemy\u548cPostgreSQL\u6765\u521b\u5efa\u7f51\u7edc\u670d\u52a1\u3002<\/h1>\n<h2>\u9996\u5148<\/h2>\n<p>\u6211\u5011\u5c07\u4f7f\u7528\u6a23\u672c\u61c9\u7528\u7a0b\u5f0f\uff08\u53cd\u994b\uff09\u4f86\u9032\u884c\u4ecb\u7d39\u3002<\/p>\n<p>\u9019\u662f\u4e00\u7bc7\u95dc\u65bcMac\u74b0\u5883\u7684\u6587\u7ae0\uff0c\u4e0d\u904eWindows\u74b0\u5883\u7684\u6b65\u9a5f\u4e5f\u662f\u76f8\u540c\u7684\u3002\u8acb\u6839\u64da\u60a8\u7684\u74b0\u5883\u66ff\u63db\u76f8\u95dc\u90e8\u5206\u4e26\u8a66\u8a66\u770b\u3002<\/p>\n<h3>Purpose<\/h3>\n<p>\u53ea\u9700\u9605\u8bfb\u672c\u6587\u5230\u6700\u540e\uff0c\u60a8\u5c31\u80fd\u591f\u505a\u5230\u4ee5\u4e0b\u7684\u4e8b\u60c5\uff1a<\/p>\n<div>\n<div class=\"post-table\">No.\u6982\u8981\u30ad\u30fc\u30ef\u30fc\u30c91Flask-SQLAlchemy\u306e\u958b\u767aFlask-SQLAlchemy, psycopg22PostgreSQL\u306e\u8a2d\u5b9apsql, Flask-Migrate<\/div>\n<\/div>\n<h3>\u6267\u884c\u73af\u5883<\/h3>\n<div>\n<div class=\"post-table\">\u74b0\u5883Ver.macOS Catalina10.15.2Python3.7.3Flask-Migrate2.5.2Flask-SQLAlchemy2.4.1Flask1.1.1psycopg22.8.4requests2.22.0<\/div>\n<\/div>\n<h3>\u6e90\u4ee3\u7801<\/h3>\n<p>\u6211\u8ba4\u4e3a\uff0c\u901a\u8fc7\u8ddf\u8e2a\u5b9e\u9645\u7684\u5b9e\u65bd\u5185\u5bb9\u548c\u6e90\u4ee3\u7801\u4e00\u8d77\u9605\u8bfb\uff0c\u53ef\u4ee5\u52a0\u6df1\u7406\u89e3\u3002\u8bf7\u52a1\u5fc5\u5145\u5206\u5229\u7528\u3002<\/p>\n<p>GitHub (Github)<\/p>\n<h3>\u76f8\u5173\u6587\u7ae0<\/h3>\n<ul class=\"post-ul\">Flask\u3067RESTful Web\u30b5\u30fc\u30d3\u30b9\u3092\u4f5c\u6210\u3059\u308b<\/ul>\n<h2>0. \u5f00\u53d1\u73af\u5883\u7684\u914d\u7f6e<\/h2>\n<pre class=\"post-pre\"><code>\/\r\n\u251c\u2500\u2500 app\r\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 __init__.py\r\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 config.py\r\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 feedback\r\n\u2502   \u2502   \u251c\u2500\u2500 __init__.py\r\n\u2502   \u2502   \u251c\u2500\u2500 common\/\r\n\u2502   \u2502   \u251c\u2500\u2500 models\r\n\u2502   \u2502   \u2502   \u251c\u2500\u2500 __init__.py\r\n\u2502   \u2502   \u2502   \u2514\u2500\u2500 feedback.py\r\n\u2502   \u2502   \u251c\u2500\u2500 static\/\r\n\u2502   \u2502   \u251c\u2500\u2500 templates\/\r\n\u2502   \u2502   \u2514\u2500\u2500 views\/\r\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 run.py\r\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 tests\/\r\n\u2514\u2500\u2500 instance\r\n  \u00a0\u00a0 \u251c\u2500\u2500 postgresql.py\r\n  \u00a0\u00a0 \u251c\u2500\u2500 sqlite3.py\r\n  \u00a0\u00a0 \u2514\u2500\u2500 config.py\r\n<\/code><\/pre>\n<h2>1. Flask-SQLAlchemy\u7684\u5f00\u53d1<\/h2>\n<h3>\u5b89\u88c5\u8f6f\u4ef6\u5305<\/h3>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u9009\u9879:<\/ol>\n<\/li>\n<\/ol>\n<p>\u5728procedure.sh\u6587\u4ef6\u4e2d\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\u5305:<br \/>\n~$ pip install Flask-Migrate<br \/>\n~$ pip install Flask-SQLAlchemy<br \/>\n~$ pip install Flask<br \/>\n~$ pip install psycopg2<\/p>\n<p>\u5982\u679c\u5728\u5b89\u88c5psycopg2\u65f6\u51fa\u73b0\u9519\u8bef\uff0c\u8bf7\u5728macOS + venv\u73af\u5883\u4e2d\u6307\u5b9a\u73af\u5883\u53d8\u91cf\u5e76\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4:<br \/>\n~$ xcode-select &#8211;install<br \/>\n~$ env LDFLAGS=&#8221;-I\/usr\/local\/opt\/openssl\/include -L\/usr\/local\/opt\/openssl\/lib&#8221; pip install psycopg2<\/p>\n<h3>SQLAlchemy\u7684\u914d\u7f6e<\/h3>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u8bbe\u5b9a\u5f00\u53d1\u73af\u5883\u7684\u914d\u7f6e\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>config.py<br \/>\n&#8220;&#8221;&#8221;instance\/config.py<br \/>\n&#8220;&#8221;&#8221;<\/p>\n<p>\u4eceinstance.postgresql\u5bfc\u5165SQLALCHEMY_DATABASE_URI\u4f5c\u4e3aDATABASE_URI<\/p>\n<p>DEBUG = True<br \/>\n# SECRET_KEY\u662f\u901a\u8fc7os.urandom(24)\u751f\u6210\u7684\u3002<br \/>\nSECRET_KEY = &#8216;\\xf7\\xf4\\x9bb\\xd7\\xa8\\xdb\\xee\\x9f\\xe3\\x98SR\\xda\\xb0@\\xb7\\x12\\xa4uB\\xda\\xa3\\x1b&#8217;<br \/>\nSTRIPE_API_KEY = &#8221;<\/p>\n<p>SQLALCHEMY_DATABASE_URI = DATABASE_URI<br \/>\nSQLALCHEMY_TRACK_MODIFICATIONS = True<br \/>\nSQLALCHEMY_ECHO = True<\/p>\n<p>\u8bbe\u5b9aPostgreSQL\u3002<\/p>\n<p>postgresql.py<br \/>\n&#8220;&#8221;&#8221;instance\/postgresql.py<br \/>\n&#8220;&#8221;&#8221;<\/p>\n<p>SQLALCHEMY_DATABASE_URI = &#8216;postgresql+psycopg2:\/\/{user}:{password}@{host}\/{name}&#8217;.format(**{<br \/>\n&#8216;user&#8217;: &#8216;nsuhara&#8217;,<br \/>\n&#8216;password&#8217;: &#8216;nsuhara&#8217;,<br \/>\n&#8216;host&#8217;: &#8216;127.0.0.1&#8217;,<br \/>\n&#8216;name&#8217;: &#8216;db.postgresql&#8217;<br \/>\n})<\/p>\n<p>\u8bbe\u5b9aSQLite3\uff08\u989d\u5916\uff09\u3002<\/p>\n<p>sqlite3.py<br \/>\n&#8220;&#8221;&#8221;instance\/sqlite3.py<br \/>\n&#8220;&#8221;&#8221;<\/p>\n<p>\u5bfc\u5165os<\/p>\n<p>SQLALCHEMY_DATABASE_URI = &#8216;sqlite:\/\/\/{host}\/{name}&#8217;.format(**{<br \/>\n&#8216;host&#8217;: os.path.dirname(os.path.abspath(__file__)),<br \/>\n&#8216;name&#8217;: &#8216;db.sqlite3&#8217;<br \/>\n})<\/p>\n<h3>\u521b\u5efaModel<\/h3>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u751f\u6210\u4e00\u4e2aSQLAlchemy\u7684\u5b9e\u4f8b\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>__init__.py<br \/>\n&#8220;&#8221;&#8221;app\/feedback\/models\/__init__.py&#8221;&#8221;&#8221;<\/p>\n<p>from flask_sqlalchemy import SQLAlchemy<\/p>\n<p>db = SQLAlchemy()<\/p>\n<p>def init():<br \/>\n&#8220;&#8221;&#8221;init&#8221;&#8221;&#8221;<br \/>\ndb.create_all()<\/p>\n<p>\u7ee7\u627fSQLAlchemy\u7684\u7c7b(db.Model)\uff0c\u521b\u5efa\u4e00\u4e2a\u6a21\u578b\u3002<\/p>\n<p>feedback.py<br \/>\n&#8220;&#8221;&#8221;app\/feedback\/models\/feedback.py&#8221;&#8221;&#8221;<\/p>\n<p>from datetime import datetime<\/p>\n<p>from feedback.models import db<\/p>\n<p>class Feedback(db.Model):<br \/>\n&#8220;&#8221;&#8221;Feedback&#8221;&#8221;&#8221;<br \/>\n__tablename__ = &#8216;feedback&#8217;<\/p>\n<p>id = db.Column(db.Integer, primary_key=True, autoincrement=True)<br \/>\nservice = db.Column(db.String(255), nullable=False)<br \/>\ntitle = db.Column(db.String(255), nullable=False)<br \/>\ndetail = db.Column(db.String(255), nullable=False)<br \/>\ncreated_date = db.Column(<br \/>\ndb.DateTime, nullable=False, default=datetime.utcnow)<\/p>\n<p>def __init__(self, service, title, detail):<br \/>\nself.service = service<br \/>\nself.title = title<br \/>\nself.detail = detail<\/p>\n<p>def to_dict(self):<br \/>\n&#8220;&#8221;&#8221;to_dict&#8221;&#8221;&#8221;<br \/>\nreturn {<br \/>\n&#8216;id&#8217;: self.id,<br \/>\n&#8216;service&#8217;: self.service,<br \/>\n&#8216;title&#8217;: self.title,<br \/>\n&#8216;detail&#8217;: self.detail,<br \/>\n&#8216;created_date&#8217;: self.created_date<br \/>\n}<\/p>\n<h2>2. PostgreSQL\u7684\u914d\u7f6e\u8bbe\u7f6e<\/h2>\n<p>\u8fd9\u662fHomebrew\u7684\u4e00\u4e2a\u793a\u4f8b\u8fd0\u884c\u3002<\/p>\n<h3>\u786e\u8ba4\u670d\u52a1<\/h3>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u67e5\u8be2\u670d\u52a1\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>procedure.sh<br \/>\n~$ brew services list<\/p>\n<p>result.sh<br \/>\n\u540d\u79f0 \u72b6\u6001 \u7528\u6237 Plist<br \/>\npostgresql \u5df2\u542f\u52a8 nsuhara \/Users\/nsuhara\/Library\/LaunchAgents\/homebrew.mxcl.postgresql.plist<\/p>\n<h3>\u670d\u52a1\u5f00\u59cb\/\u7ed3\u675f<\/h3>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u542f\u52a8\u670d\u52a1\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>procedure.sh<br \/>\n~$ brew services start postgresql<\/p>\n<p>\u505c\u6b62\u670d\u52a1\u3002<\/p>\n<p>procedure.sh<br \/>\n~$ brew services stop postgresql<\/p>\n<h3>\u67e5\u8be2\u6570\u636e\u5e93<\/h3>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u786e\u8ba4\u6570\u636e\u5e93\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4f1a\u521b\u5efa\u4e09\u4e2a\u6570\u636e\u5e93\u3002\u6b64\u5916\uff0cMac\u7684\u7528\u6237\u540d\u4f1a\u88ab\u8bbe\u7f6e\u4e3aOwner\u3002<\/p>\n<p>procedure.sh<br \/>\n~$ psql -l<\/p>\n<p>result.sh<br \/>\n\u6570\u636e\u5e93\u5217\u8868<br \/>\n\u540d\u79f0 | \u6240\u6709\u8005 | \u7f16\u7801 | \u533a\u57df | \u7c7b\u578b | \u8bbf\u95ee\u6743\u9650<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\npostgres | nsuhara | UTF8 | C | C |<br \/>\ntemplate0 | nsuhara | UTF8 | C | C | =c\/nsuhara +<br \/>\n| | | | | nsuhara=CTc\/nsuhara<br \/>\ntemplate1 | nsuhara | UTF8 | C | C | =c\/nsuhara +<br \/>\n| | | | | nsuhara=CTc\/nsuhara<\/p>\n<h3>\u8fde\u63a5\/\u65ad\u5f00\u6570\u636e\u5e93<\/h3>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u8fde\u63a5\u5230\u6570\u636e\u5e93\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>procedure.sh<br \/>\n~$ psql -h &#8220;&#8221; -p -U &#8220;&#8221; -d &#8220;&#8221;<\/p>\n<p>example.sh<br \/>\n~$ psql -h &#8220;127.0.0.1&#8221; -p 5432 -U &#8220;nsuhara&#8221; -d &#8220;postgres&#8221;<\/p>\n<p>\u65ad\u5f00\u6570\u636e\u5e93\u8fde\u63a5\u3002<\/p>\n<p>procedure.sh<br \/>\npostgresql=# \\q<\/p>\n<h3>\u521b\u5efa\u7528\u6237\u89d2\u8272<\/h3>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u8fde\u63a5\u5230\u6570\u636e\u5e93\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>\u786e\u8ba4\u89d2\u8272\uff08\u7528\u6237\uff09\u3002<\/p>\n<p>procedure.sh<br \/>\npostgresql=# \\du<\/p>\n<p>result.sh<br \/>\n\u89d2\u8272\u5217\u8868<br \/>\n\u89d2\u8272\u540d\u79f0 | \u5c5e\u6027 | \u6240\u5c5e\u6210\u5458<br \/>\n&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8211;<br \/>\nnsuhara | \u8d85\u7ea7\u7528\u6237, \u521b\u5efa\u89d2\u8272, \u521b\u5efa\u6570\u636e\u5e93, \u590d\u5236, \u65c1\u8defRLS | {}<\/p>\n<p>\u521b\u5efa\u89d2\u8272\uff08\u7528\u6237\uff09\u3002<\/p>\n<p>procedure.sh<br \/>\npostgresql=# CREATE ROLE &#8220;&#8221; LOGIN PASSWORD &#8220;password&#8221;;<\/p>\n<p>example.sh<br \/>\npostgresql=# CREATE ROLE &#8220;nsuhara&#8221; LOGIN PASSWORD &#8220;nsuhara&#8221;;<\/p>\n<p>\u5220\u9664\u89d2\u8272\uff08\u7528\u6237\uff09\u3002<\/p>\n<p>procedure.sh<br \/>\npostgresql=# DROP ROLE &#8220;&#8221;;<\/p>\n<p>example.sh<br \/>\npostgresql=# DROP ROLE &#8220;nsuhara&#8221;;<\/p>\n<h3>\u521b\u5efa\u6570\u636e\u5e93<\/h3>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u8fde\u63a5\u5230\u6570\u636e\u5e93\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u786e\u8ba4\u6570\u636e\u5e93\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>procedure.sh<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>postgresql=# \\l<\/ol>\n<\/li>\n<\/ol>\n<p>result.sh<br \/>\n\u6570\u636e\u5e93\u5217\u8868<br \/>\n\u540d\u79f0 | \u6240\u6709\u8005 | \u7f16\u7801 | \u6821\u5bf9\u987a\u5e8f | \u7c7b\u578b | \u8bbf\u95ee\u6743\u9650<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\ndb.postgresql | nsuhara | UTF8 | C | C |<br \/>\npostgres | nsuhara | UTF8 | C | C |<br \/>\ntemplate0 | nsuhara | UTF8 | C | C | =c\/nsuhara +<br \/>\n| | | | | nsuhara=CTc\/nsuhara<br \/>\ntemplate1 | nsuhara | UTF8 | C | C | =c\/nsuhara +<br \/>\n| | | | | nsuhara=CTc\/nsuhara<\/p>\n<p>\u521b\u5efa\u6570\u636e\u5e93\u3002<br \/>\nprocedure.sh<br \/>\npostgresql=# CREATE DATABASE &#8220;&#8221; OWNER &#8220;&#8221;;<\/p>\n<p>example.sh<br \/>\npostgresql=# CREATE DATABASE &#8220;db.postgresql&#8221; OWNER &#8220;nsuhara&#8221;;<\/p>\n<p>\u5220\u9664\u6570\u636e\u5e93\u3002<br \/>\nprocedure.sh<br \/>\npostgresql=# DROP DATABASE &#8220;&#8221;;<\/p>\n<p>example.sh<br \/>\npostgresql=# DROP DATABASE &#8220;db.postgresql&#8221;;<\/p>\n<h3>\u6570\u636e\u5e93\u8fc1\u79fb<\/h3>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5728Python\u4e2d\u8bbe\u7f6eFlask\u7684\u73af\u5883\u53d8\u91cf\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u6267\u884c\u6570\u636e\u5e93\u8fc1\u79fb\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5728procedure.sh\u6587\u4ef6\u4e2d\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>~$ flask db init<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>~$ flask db migrate<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>~$ flask db upgrade<\/ol>\n<h3>\u5220\u9664\u8bb0\u5f55<\/h3>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u8fde\u63a5\u5230\u6570\u636e\u5e93\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>\u5220\u9664\u8bb0\u5f55\u3002<\/p>\n<p>procedure.sh<br \/>\npostgresql=# \u4ece\u4e2d\u5220\u9664;<\/p>\n<p>\u521d\u59cb\u5316\u81ea\u52a8\u7f16\u53f7\u3002<\/p>\n<p>procedure.sh<br \/>\npostgresql=# \u9009\u62e9setval(&#8216;_id_seq&#8217;, 1, false);<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528Flask-SQLAlchemy\u548cPostgreSQL\u6765\u521b\u5efa\u7f51\u7edc\u670d\u52a1\u3002 \u9996\u5148 \u6211\u5011\u5c07\u4f7f\u7528\u6a23\u672c\u61c9\u7528\u7a0b\u5f0f\uff08\u53cd\u994b [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-42007","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4f7f\u7528Flask-SQLAlchemy\u548cPostgreSQL\u6765\u521b\u5efaWeb\u670d\u52a1 - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528flask-sqlalchemy\u548cpostgresql\u6765\u521b\u5efaweb\u670d\u52a1\u3002\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4f7f\u7528Flask-SQLAlchemy\u548cPostgreSQL\u6765\u521b\u5efaWeb\u670d\u52a1\" \/>\n<meta property=\"og:description\" content=\"\u4f7f\u7528Flask-SQLAlchemy\u548cPostgreSQL\u6765\u521b\u5efa\u7f51\u7edc\u670d\u52a1\u3002 \u9996\u5148 \u6211\u5011\u5c07\u4f7f\u7528\u6a23\u672c\u61c9\u7528\u7a0b\u5f0f\uff08\u53cd\u994b [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528flask-sqlalchemy\u548cpostgresql\u6765\u521b\u5efaweb\u670d\u52a1\u3002\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2024-02-20T05:47:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-30T09:19:33+00:00\" \/>\n<meta name=\"author\" content=\"\u6e05, \u626c\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u6e05, \u626c\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8flask-sqlalchemy%e5%92%8cpostgresql%e6%9d%a5%e5%88%9b%e5%bb%baweb%e6%9c%8d%e5%8a%a1%e3%80%82\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8flask-sqlalchemy%e5%92%8cpostgresql%e6%9d%a5%e5%88%9b%e5%bb%baweb%e6%9c%8d%e5%8a%a1%e3%80%82\/\",\"name\":\"\u4f7f\u7528Flask-SQLAlchemy\u548cPostgreSQL\u6765\u521b\u5efaWeb\u670d\u52a1 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2024-02-20T05:47:39+00:00\",\"dateModified\":\"2024-04-30T09:19:33+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8flask-sqlalchemy%e5%92%8cpostgresql%e6%9d%a5%e5%88%9b%e5%bb%baweb%e6%9c%8d%e5%8a%a1%e3%80%82\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8flask-sqlalchemy%e5%92%8cpostgresql%e6%9d%a5%e5%88%9b%e5%bb%baweb%e6%9c%8d%e5%8a%a1%e3%80%82\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8flask-sqlalchemy%e5%92%8cpostgresql%e6%9d%a5%e5%88%9b%e5%bb%baweb%e6%9c%8d%e5%8a%a1%e3%80%82\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4f7f\u7528Flask-SQLAlchemy\u548cPostgreSQL\u6765\u521b\u5efaWeb\u670d\u52a1\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461\",\"name\":\"\u6e05, \u626c\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g\",\"caption\":\"\u6e05, \u626c\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyang\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8flask-sqlalchemy%e5%92%8cpostgresql%e6%9d%a5%e5%88%9b%e5%bb%baweb%e6%9c%8d%e5%8a%a1%e3%80%82\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u4f7f\u7528Flask-SQLAlchemy\u548cPostgreSQL\u6765\u521b\u5efaWeb\u670d\u52a1 - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528flask-sqlalchemy\u548cpostgresql\u6765\u521b\u5efaweb\u670d\u52a1\u3002\/","og_locale":"zh_CN","og_type":"article","og_title":"\u4f7f\u7528Flask-SQLAlchemy\u548cPostgreSQL\u6765\u521b\u5efaWeb\u670d\u52a1","og_description":"\u4f7f\u7528Flask-SQLAlchemy\u548cPostgreSQL\u6765\u521b\u5efa\u7f51\u7edc\u670d\u52a1\u3002 \u9996\u5148 \u6211\u5011\u5c07\u4f7f\u7528\u6a23\u672c\u61c9\u7528\u7a0b\u5f0f\uff08\u53cd\u994b [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528flask-sqlalchemy\u548cpostgresql\u6765\u521b\u5efaweb\u670d\u52a1\u3002\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2024-02-20T05:47:39+00:00","article_modified_time":"2024-04-30T09:19:33+00:00","author":"\u6e05, \u626c","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u6e05, \u626c","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8flask-sqlalchemy%e5%92%8cpostgresql%e6%9d%a5%e5%88%9b%e5%bb%baweb%e6%9c%8d%e5%8a%a1%e3%80%82\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8flask-sqlalchemy%e5%92%8cpostgresql%e6%9d%a5%e5%88%9b%e5%bb%baweb%e6%9c%8d%e5%8a%a1%e3%80%82\/","name":"\u4f7f\u7528Flask-SQLAlchemy\u548cPostgreSQL\u6765\u521b\u5efaWeb\u670d\u52a1 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2024-02-20T05:47:39+00:00","dateModified":"2024-04-30T09:19:33+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8flask-sqlalchemy%e5%92%8cpostgresql%e6%9d%a5%e5%88%9b%e5%bb%baweb%e6%9c%8d%e5%8a%a1%e3%80%82\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8flask-sqlalchemy%e5%92%8cpostgresql%e6%9d%a5%e5%88%9b%e5%bb%baweb%e6%9c%8d%e5%8a%a1%e3%80%82\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8flask-sqlalchemy%e5%92%8cpostgresql%e6%9d%a5%e5%88%9b%e5%bb%baweb%e6%9c%8d%e5%8a%a1%e3%80%82\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u4f7f\u7528Flask-SQLAlchemy\u548cPostgreSQL\u6765\u521b\u5efaWeb\u670d\u52a1"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461","name":"\u6e05, \u626c","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g","caption":"\u6e05, \u626c"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyang\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8flask-sqlalchemy%e5%92%8cpostgresql%e6%9d%a5%e5%88%9b%e5%bb%baweb%e6%9c%8d%e5%8a%a1%e3%80%82\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/42007","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=42007"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/42007\/revisions"}],"predecessor-version":[{"id":93238,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/42007\/revisions\/93238"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=42007"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=42007"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=42007"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}