Home > OS >  OperationalError: attempt to write a readonly DB on Vercel via Github (the DB and its folder are ful
OperationalError: attempt to write a readonly DB on Vercel via Github (the DB and its folder are ful

Time:01-20

I am trying to deploy a simple Flask app with a SQLite database. It works fine when running locally. I deploy it on Vercel via Github. It works until it needs to write to the db. Then there is

OperationalError: attempt to write a readonly database

Both the DB and the folder ‘instance’ that contains it are Full-access on my local system, I can see it with

attrib ~/instance 

in the command line (I am working with Windows 10). Is there a way to check and change the access mode of a file or a folder right on the Github repo?

Here are the logs regarding this error:

[ERROR] 2023-01-12T17:19:33.931Z    63bacb5b-ec13-4247-b784-9aaba99376a0
    Exception on /register [POST]Traceback (most recent call last):
  File "/var/task/sqlalchemy/engine/base.py", line 1900, in _execute_context    self.dialect.do_execute
(  File "/var/task/sqlalchemy/engine/default.py", line 736, in do_execute    cursor.execute(statement, parameters)
sqlite3.OperationalError: attempt to write a readonly database
The above exception was the direct cause of the following exception:
Traceback (most recent call last):  File "/var/task/flask/app.py", line 2525, in wsgi_app    response = self.full_dispatch_request()  File "/var/task/flask/app.py", line 1822, in full_dispatch_request    rv = self.handle_user_exception(e)  File "/var/task/flask/app.py", line 1820, in full_dispatch_request    rv = self.dispatch_request()  File "/var/task/flask/app.py", line 1796, in dispatch_request    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  File "./app.py", line 136, in register    db.session.commit()  
File "<string>", line 2, in commit  File "/var/task/sqlalchemy/orm/session.py", line 1451, in commit    self._transaction.commit(_to_root=self.future)  File "/var/task/sqlalchemy/orm/session.py", line 829, in commit    self._prepare_impl()  File "/var/task/sqlalchemy/orm/session.py", line 808, in _prepare_impl    self.session.flush()  File "/var/task/sqlalchemy/orm/session.py", line 3444, in flush    self._flush(objects)  File "/var/task/sqlalchemy/orm/session.py", line 3584, in _flush    transaction.rollback(_capture_exception=True)  File "/var/task/sqlalchemy/util/langhelpers.py", line 70, in __exit__    compat.raise_(  File "/var/task/sqlalchemy/util/compat.py", line 211, in raise_    raise exception  File "/var/task/sqlalchemy/orm/session.py", line 3544, in _flush    flush_context.execute()  File "/var/task/sqlalchemy/orm/unitofwork.py", line 456, in execute    rec.execute(self)  File "/var/task/sqlalchemy/orm/unitofwork.py", line 630, in execute    util.preloaded.orm_persistence.save_obj(  File "/var/task/sqlalchemy/orm/persistence.py", line 245, in save_obj    _emit_insert_statements(  File "/var/task/sqlalchemy/orm/persistence.py", line 1238, in _emit_insert_statements    result = connection._execute_20(  File "/var/task/sqlalchemy/engine/base.py", line 1705, in _execute_20    return meth(self, args_10style, kwargs_10style, execution_options)  File "/var/task/sqlalchemy/sql/elements.py", line 334, in _execute_on_connection    return connection._execute_clauseelement(  File "/var/task/sqlalchemy/engine/base.py", line 1572, in _execute_clauseelement    ret = self._execute_context(  File "/var/task/sqlalchemy/engine/base.py", line 1943, in _execute_context    self._handle_dbapi_exception(  File "/var/task/sqlalchemy/engine/base.py", line 2124, in _handle_dbapi_exception    util.raise_(  File "/var/task/sqlalchemy/util/compat.py", line 211, in raise_    raise exception  File "/var/task/sqlalchemy/engine/base.py", line 1900, in _execute_context    self.dialect.do_execute(  File "/var/task/sqlalchemy/engine/default.py", line 736, in do_execute    cursor.execute(statement, parameters)sqlalchemy.exc.
OperationalError: (sqlite3.OperationalError) attempt to write a readonly database

I double-checked the access mode of the DB in my local system both as User and as Admin

CodePudding user response:

It turns out that Vercel does not support SQLite. It is clearly written in their guides:

SQLite needs a local file system on the server to store the data permanently when write requests are made. In a serverless environment, this central single permanent storage is not available because storage is ephemeral with serverless functions.

So it's not the problem of a Read-only mode, but rather the issue with SQL databases on Vercel.

  • Related