• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python db.create_all函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中models.db.create_all函数的典型用法代码示例。如果您正苦于以下问题:Python create_all函数的具体用法?Python create_all怎么用?Python create_all使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了create_all函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: create_app

def create_app():
    app = Flask(__name__)
    app.secret_key = 'super~~~~~~~~~~~~'

    # url
    app.register_blueprint(welcome_page)
    app.register_blueprint(auth_page)

    # db
    if socket.gethostname() == 'lihaichuangdeMac-mini.local':
        print(1)
        app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://sctlee:[email protected]:3306/singledog'
    else:
        print(2)
        conn_string = 'mysql+pymysql://%s:%[email protected]%s:%s/%s' % (os.getenv('MYSQL_USERNAME'), os.getenv('MYSQL_PASSWORD'),\
                      os.getenv('MYSQL_PORT_3306_TCP_ADDR'), os.getenv('MYSQL_PORT_3306_TCP_PORT'),\
                      os.getenv('MYSQL_INSTANCE_NAME'))
        print(conn_string)
        app.config['SQLALCHEMY_DATABASE_URI'] = conn_string

    db.init_app(app)

    from models import User
    db.create_all(app=app)

    # login manager
    login_manager.init_app(app)

    @app.before_request
    def before_request():
        g.user = current_user

    return app
开发者ID:sctlee,项目名称:flask-docker,代码行数:33,代码来源:app.py


示例2: init_db

def init_db():
    db.drop_all()
    db.create_all()
    type_ids = {}
    rate_type_ids = {}
    for type_name in ["office", "meeting", "other"]:
        t = ListingType(type_name)
        db.session.add(t)
        db.session.commit()
        type_ids[type_name] = t
    for type_name in ["Hour", "Day", "Week", "Month", "3 Months", "6 Months", "Year"]:
        t = RateType(type_name)
        db.session.add(t)
        db.session.commit()
        rate_type_ids[type_name] = t
    db.session.add(Listing(address="1500 Union Ave #2500, Baltimore, MD",
                           lat="39.334497", lon="-76.64081",
                           name="Headquarters for Maryland Nonprofits", space_type=type_ids["office"], price=2500,
                           description="""Set in beautiful downtown Baltimore, this is the perfect space for you.

1800 sq ft., with spacious meeting rooms.

Large windows, free wifi, free parking, quiet neighbors.""", contact_phone="55555555555", rate_type=rate_type_ids['Month']))
    db.session.add(Listing(address="6695 Dobbin Rd, Columbia, MD",
                           lat="39.186198", lon="-76.824842",
                           name="Frisco Taphouse and Brewery", space_type=type_ids["meeting"], price=1700,
                           description="""Large open space in a quiet subdivision near Columbia.

High ceilings, lots of parking, good beer selection.""", rate_type=rate_type_ids['Day'], contact_phone="55555555555", expires_in_days=-1))
    db.session.add(Account("admin", "[email protected]", "Pass1234"))
    db.session.commit()
开发者ID:josephturnerjr,项目名称:spacefinder,代码行数:31,代码来源:db_functions.py


示例3: startup

def startup():

    # db initializations
    db.create_all()
    settings = Settings(secret_key=pyotp.random_base32())
    db.session.add(settings)
    db.session.commit()
开发者ID:Conway,项目名称:anonpost,代码行数:7,代码来源:flask_app.py


示例4: run

	def run(self):
		db.drop_all()
		db.create_all()
		db.session.add(Group('Diggers', 'Preschool'))
		db.session.add(Group('Discoverers', 'Year R-2'))
		db.session.add(Group('Explorers', 'Years 3-6'))
		db.session.commit()
开发者ID:nathan3000,项目名称:lesson_aims,代码行数:7,代码来源:manage.py


示例5: setUp

    def setUp(self):
        """
        Set up the database for use

        :return: no return
        """
        db.create_all()
开发者ID:jonnybazookatone,项目名称:gut-service,代码行数:7,代码来源:test_big_share_epic.py


示例6: home

def home():
	db.create_all()
	print request.values.get('From') + " said: " + request.values.get('Body')
	number = Numbers(request.values.get('From'))
	resp = twilio.twiml.Response()
	resp.message("Thx for stopping by Intro to API's at HackHERS! For all material, check out: https://goo.gl/2knLba")
	return str(resp)
开发者ID:jayrav13,项目名称:hackhers-apiworkshop,代码行数:7,代码来源:app.py


示例7: test

def test():
    from cron import poll

    # Make sure tables exist. If not, create them
    try:
        db.session.query(User).first()
        db.session.query(Snipe).first()
    except Exception:
        db.create_all()

    soc = Soc()
    math_courses = soc.get_courses(640)
    open_courses = poll(640, result = True)
    for dept, sections in open_courses.iteritems():
        open_courses[dept] = [section.number for section in sections]

    success = True

    for math_course in math_courses:
        course_number = math_course['courseNumber']

        if course_number.isdigit():
            course_number = str(int(course_number))

        for section in math_course['sections']:
            section_number = section['number']
            if section_number.isdigit():
                section_number = str(int(section_number))

            if section['openStatus'] and not section_number in open_courses[course_number]:
                raise Exception('Test failed')
                success = False

    return success
开发者ID:vivekseth,项目名称:sniper,代码行数:34,代码来源:app.py


示例8: setUp

    def setUp(self):
        db.create_all()
        a_simple_model = SimpleModel()
        a_simple_model.app_name = "simple_app"

        db.session.add(a_simple_model)
        db.session.commit()
开发者ID:mukund-kri,项目名称:flask-sqlalchemy-f5-template,代码行数:7,代码来源:home_tests.py


示例9: create_app

def create_app():
    app = flask.Flask("app")
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
    app.register_blueprint(api)
    db.init_app(app)
    with app.app_context():
        db.create_all()
    return app
开发者ID:chfw,项目名称:sample,代码行数:8,代码来源:application.py


示例10: run

 def run(app=app):
     """
     Creates the database in the application context
     :return: no return
     """
     with app.app_context():
         db.create_all()
         db.session.commit()
开发者ID:ehenneken,项目名称:harbour-service,代码行数:8,代码来源:manage.py


示例11: testdb

def testdb():
  #if db.session.query("1").from_statement("SELECT 1").all():
  #  return 'It works.'
  #else:
  #  return 'Something is broken.'   
  db.drop_all()
  db.create_all()
  return "i got here"
开发者ID:jacobduron90,项目名称:flaskDrinks,代码行数:8,代码来源:app.py


示例12: setUp

 def setUp(self):
     app = Flask("tests", static_url_path="/static")
     app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
     app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:////tmp/test_idb.db"
     db.init_app(app)
     db.app = app
     db.configure_mappers()
     db.create_all()
开发者ID:tweetcity,项目名称:cs373-idb,代码行数:8,代码来源:tests.py


示例13: setUp

 def setUp(self):
     self.app = create_app('test_config')
     self.test_client = self.app.test_client()
     self.app_context = self.app.app_context()
     self.app_context.push()
     self.test_user_name = 'testuser'
     self.test_user_password = 'T3s!p4s5w0RDd12#'
     db.create_all()
开发者ID:xianjunzhengbackup,项目名称:code,代码行数:8,代码来源:test_views.py


示例14: create_app

def create_app():
	app = Flask(__name__)
	app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///stress.db'
	app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
	db.init_app(app)
	with app.app_context():
		db.create_all()
	return app
开发者ID:xMrWhite,项目名称:Affektive,代码行数:8,代码来源:main.py


示例15: init_db

def init_db():
    if app.config["DB_CREATED"]:
        app.logger.warning("Someone (%s) tried to access init_db" % get_client_ip())
        return redirect(url_for("show_index"))
    else:
        db.create_all()
        app.logger.info("%s created database tables with /init_db" % get_client_ip())
        flash("Database created, please update config.py")
        return redirect(url_for("show_index"))
开发者ID:rnts08,项目名称:flask-boilerplate,代码行数:9,代码来源:webapp.py


示例16: create_app

def create_app():
    api = Flask('api')
    api.register_blueprint(person_blueprint)
    db.init_app(api)

    with api.app_context():
        db.create_all()

    return api
开发者ID:drimer,项目名称:example-codes,代码行数:9,代码来源:app.py


示例17: init_db

def init_db():
    if app.config['DB_CREATED']:
        app.logger.warning('Someone (%s) tried to access init_db' % get_client_ip())
        return redirect( url_for('show_index') )
    else:
        db.create_all()
        app.logger.info('%s created database tables with /init_db' % get_client_ip())
        flash('Database created, please update config.py')
        return redirect( url_for('show_index') )
开发者ID:saibotd,项目名称:flask-boilerplate,代码行数:9,代码来源:webapp.py


示例18: setUp

    def setUp(self):
        """
        Set up the database for use

        :return: no return
        """
        db.create_all()
        self.stub_library, self.stub_uid = StubDataLibrary().make_stub()
        self.stub_document = StubDataDocument().make_stub()
开发者ID:jonnybazookatone,项目名称:gut-service,代码行数:9,代码来源:test_job_epic.py


示例19: create_app

def create_app():
    """Create your application."""
    app = Flask(__name__)
    app.config.from_object(settings)
    app.register_module(views)
    db.app = app
    db.init_app(app)
    db.create_all()
    return app
开发者ID:codeforamerica,项目名称:open_data_upload,代码行数:9,代码来源:__init__.py


示例20: create_app

    def create_app():
        app = flask.Flask("app")
        app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:[email protected]/clientmanager'
        db.init_app(app)
        with app.app_context():
            # Extensions like Flask-SQLAlchemy now know what the "current" app
            # is while within this block. Therefore, you can now run........
            db.create_all()

        return None
开发者ID:fabiancabau,项目名称:clientmanager,代码行数:10,代码来源:db_create.py



注:本文中的models.db.create_all函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python db.drop_all函数代码示例发布时间:2022-05-27
下一篇:
Python db.commit函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap