Şimdi Ara

Python Flask ile veri tabanı

Daha Fazla
Bu Konudaki Kullanıcılar: Daha Az
2 Misafir - 2 Masaüstü
5 sn
11
Cevap
0
Favori
1.202
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
0 oy
Öne Çıkar
Sayfa: 1
Giriş
Mesaj
  • Merhaba, flask öğrenmeye başladım ama veritabanını ya hiç oluşturamıyorum ya da oluştursam bile bağlantıyı bir türlü kuramıyorum. Bu konuyla ilgili çok video izledim ama onların yaptıklarını birebir yapmama rağmen olmuyor sanırım başka ayarları da var. Bir de genelde mysql kullanıyorlar neden sqlite3 kullanmıyorlar onu da merak ettim. flaskda veritabanı oluşturma ve bağlanma ile ilgili kaynak paylaşabilecek varsa sevinirim, teşekkürler.



  • Yaptığınız adımları sayar mısınız?

    < Bu ileti mini sürüm kullanılarak atıldı >
  • CarnageTR C kullanıcısına yanıt
    aşağıda kısaca özetlemeye çalıştım

    cmd ile sqlite3 example.db komutuyla veritabanını çalıştığım kalsörde oluşturdum

    pip intall flask_sqlalchemy yükledim


    bir example.py dosyası oluşturdum, siteden mevcut kodları kopyaladım ve bağlantıyı yolunu aşağıdaki gibi belirttim
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////Users/user/Python/untitled4/example.db'

    terminalden pythonu çalıştırıp
    from example import db
    yazdım bu kod çalıştı ama sonraki
    db.create_all()
    kodu farklı videolarda ve dökümanlardaki adımları uygulasam bile hep hata verdi
  • wyilldirim kullanıcısına yanıt
    Hata kodu nedir? Tüm içeriği yazabilir misiniz? Böyle anlamak imkansız.

    < Bu ileti mobil sürüm kullanılarak atıldı >
  • CarnageTR C kullanıcısına yanıt
    Flask ile yapamayınca Django'ya geçtim ama yine de Flask ile de yapmak isterim. terminalde çıkan hatayı aşağıda paylaşıyorum

    >>> from example import db

    >>> db.create_all()
    Traceback (most recent call last):
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\base.py", line 2262, in _wrap_pool_connect
    return fn()
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 363, in connect
    return _ConnectionFairy._checkout(self)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 760, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 492, in checkout
    rec = pool._do_get()
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\impl.py", line 238, in _do_get
    return self._create_connection()
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 308, in _create_connection
    return _ConnectionRecord(self)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 437, in __init__
    self.__connect(first_connect_check=True)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 639, in __connect
    connection = pool._invoke_creator(self)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\strategies.py", line 114, in connect
    return dialect.connect(*cargs, **cparams)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\default.py", line 451, in connect
    return self.dbapi.connect(*cargs, **cparams)
    sqlite3.OperationalError: unable to open database file

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "C:\Users\user\Python\untitled4\lib\site-packages\flask_sqlalchemy\__init__.py", line 1033, in create_all
    self._execute_for_all_tables(app, bind, 'create_all')
    File "C:\Users\user\Python\untitled4\lib\site-packages\flask_sqlalchemy\__init__.py", line 1025, in _execute_for_all_tables
    op(bind=self.get_engine(app, bind), **extra)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\sql\schema.py", line 4287, in create_all
    ddl.SchemaGenerator, self, checkfirst=checkfirst, tables=tables
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\base.py", line 2032, in _run_visitor
    with self._optional_conn_ctx_manager(connection) as conn:
    File "C:\Python\Python37-32\lib\contextlib.py", line 112, in __enter__
    return next(self.gen)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\base.py", line 2024, in _optional_conn_ctx_manager
    with self._contextual_connect() as conn:
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\base.py", line 2226, in _contextual_connect
    self._wrap_pool_connect(self.pool.connect, None),
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\base.py", line 2266, in _wrap_pool_connect
    e, dialect, self
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\base.py", line 1536, in _handle_dbapi_exception_noconnection
    util.raise_from_cause(sqlalchemy_exception, exc_info)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\util\compat.py", line 383, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\util\compat.py", line 128, in reraise
    raise value.with_traceback(tb)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\base.py", line 2262, in _wrap_pool_connect
    return fn()
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 363, in connect
    return _ConnectionFairy._checkout(self)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 760, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 492, in checkout
    rec = pool._do_get()
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\impl.py", line 238, in _do_get
    return self._create_connection()
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 308, in _create_connection
    return _ConnectionRecord(self)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 437, in __init__
    self.__connect(first_connect_check=True)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 639, in __connect
    connection = pool._invoke_creator(self)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\strategies.py", line 114, in connect
    return dialect.connect(*cargs, **cparams)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\default.py", line 451, in connect
    return self.dbapi.connect(*cargs, **cparams)
    sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file
    (Background on this error at:
    sqlalche.me
    400 Bad Request
    http://sqlalche.me/e/e3q8)

    >>>




  • bu satırı 'sqlite:////Users/user/Python/untitled4/example.db'
    bununla 'sqlite:///Users/user/Python/untitled4/example.db' değiştir. sonurun çözülmesi lazım.

    Windowstaki öne slash işi olayı sürekli karıştırıyor. Docker üzerinden linux makine kullanırsan dev ortamın çok daha kullanışlı olur.
  • CarnageTR C kullanıcısına yanıt
    maalesef yine hata verdi sanırım çok farklı bir sorun var

    >>> db.create_all()
    Traceback (most recent call last):
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\base.py", line 2262, in _wrap_pool_connect
    return fn()
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 363, in connect
    return _ConnectionFairy._checkout(self)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 760, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 492, in checkout
    rec = pool._do_get()
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\impl.py", line 238, in _do_get
    return self._create_connection()
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 308, in _create_connection
    return _ConnectionRecord(self)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 437, in __init__
    self.__connect(first_connect_check=True)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 639, in __connect
    connection = pool._invoke_creator(self)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\strategies.py", line 114, in connect
    return dialect.connect(*cargs, **cparams)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\default.py", line 451, in connect
    return self.dbapi.connect(*cargs, **cparams)
    sqlite3.OperationalError: unable to open database file

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "C:\Users\user\Python\untitled4\lib\site-packages\flask_sqlalchemy\__init__.py", line 1033, in create_all
    self._execute_for_all_tables(app, bind, 'create_all')
    File "C:\Users\user\Python\untitled4\lib\site-packages\flask_sqlalchemy\__init__.py", line 1025, in _execute_for_all_tables
    op(bind=self.get_engine(app, bind), **extra)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\sql\schema.py", line 4287, in create_all
    ddl.SchemaGenerator, self, checkfirst=checkfirst, tables=tables
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\base.py", line 2032, in _run_visitor
    with self._optional_conn_ctx_manager(connection) as conn:
    File "C:\Python\Python37-32\lib\contextlib.py", line 112, in __enter__
    return next(self.gen)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\base.py", line 2024, in _optional_conn_ctx_manager
    with self._contextual_connect() as conn:
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\base.py", line 2226, in _contextual_connect
    self._wrap_pool_connect(self.pool.connect, None),
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\base.py", line 2266, in _wrap_pool_connect
    e, dialect, self
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\base.py", line 1536, in _handle_dbapi_exception_noconnection
    util.raise_from_cause(sqlalchemy_exception, exc_info)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\util\compat.py", line 383, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\util\compat.py", line 128, in reraise
    raise value.with_traceback(tb)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\base.py", line 2262, in _wrap_pool_connect
    return fn()
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 363, in connect
    return _ConnectionFairy._checkout(self)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 760, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 492, in checkout
    rec = pool._do_get()
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\impl.py", line 238, in _do_get
    return self._create_connection()
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 308, in _create_connection
    return _ConnectionRecord(self)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 437, in __init__
    self.__connect(first_connect_check=True)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\pool\base.py", line 639, in __connect
    connection = pool._invoke_creator(self)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\strategies.py", line 114, in connect
    return dialect.connect(*cargs, **cparams)
    File "C:\Users\user\Python\untitled4\lib\site-packages\sqlalchemy\engine\default.py", line 451, in connect
    return self.dbapi.connect(*cargs, **cparams)
    sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file
    (Background on this error at:
    sqlalche.me
    400 Bad Request
    http://sqlalche.me/e/e3q8)




  • Yapay Zeka’dan İlgili Konular
    SQL ve Python hk.
    geçen yıl önce açıldı
    Daha Fazla Göster
  • Bunu deneyin

    sqlite:\\\Users\\user\\Python\\untitled4\\example.db

    < Bu ileti mini sürüm kullanılarak atıldı >
  • CarnageTR C kullanıcısına yanıt
    yardımlarınız için çok teşekkür ederim ama bunda ise faklı bir yerde hata verdi

    >>> from example import db
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "C:\Users\user\Python\untitled4\example.py", line 7
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:\\\Users\\user\\Python\\untitled4\\example.db'
    ^
    SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 9-10: truncated \UXXXXXXXX escape
    >>> db.create_all()
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    NameError: name 'db' is not defined
    >>>
  • ufak bir değişiklik yaptım çalıştı

    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///C:\\Users\\user\\Python\\untitled4\\example.db'
    >>> from example import db
    C:\Users\user\Python\untitled4\lib\site-packages\flask_sqlalchemy\__init__.py:835: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning.
    'SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and '
    >>> db.create_all()
    >>>
  • 
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.