Ошибка attempt to write a readonly database

I have a SQLite database that I am using for a website. The problem is that when I try to INSERT INTO it, I get a PDOException

SQLSTATE[HY000]: General error: 8 attempt to write a readonly database

I SSH’d into the server and checked permissions, and the database has the permissions

-rw-rw-r--

I’m not that familiar with *nix permissions, but I’m pretty sure this means

  • Not a directory
  • Owner has read/write permissions (that’s me, according to ls -l)
  • Group has read/write permissions
  • Everyone else only has read permissions

I also looked everywhere I knew to using the sqlite3 program, and found nothing relevant.

Because I didn’t know with what permissions PDO is trying to open the database, I did

chmod o+w supplies.db

Now, I get another PDOException:

SQLSTATE[HY000]: General error: 14 unable to open database file

But it ONLY occurs when I try to execute an INSERT query after the database is open.

Any ideas on what is going on?

StayOnTarget's user avatar

StayOnTarget

11.8k10 gold badges52 silver badges84 bronze badges

asked Jul 23, 2010 at 14:31

Austin Hyde's user avatar

Austin HydeAustin Hyde

26.4k28 gold badges96 silver badges129 bronze badges

3

The problem, as it turns out, is that the PDO SQLite driver requires that if you are going to do a write operation (INSERT,UPDATE,DELETE,DROP, etc), then the folder the database resides in must have write permissions, as well as the actual database file.

I found this information in a comment at the very bottom of the PDO SQLite driver manual page.

answered Jul 25, 2010 at 19:08

Austin Hyde's user avatar

Austin HydeAustin Hyde

26.4k28 gold badges96 silver badges129 bronze badges

7

This can happen when the owner of the SQLite file itself is not the same as the user running the script. Similar errors can occur if the entire directory path (meaning each directory along the way) can’t be written to.

Who owns the SQLite file? You?

Who is the script running as? Apache or Nobody?

answered Jul 23, 2010 at 14:35

Charles's user avatar

7

For me the issue was SELinux enforcement rather than permissions. The «read only database» error went away once I disabled enforcement, following the suggestion made by Steve V. in a comment on the accepted answer.

echo 0 >/selinux/enforce

Upon running this command, everything worked as intended (CentOS 6.3).

The specific issue I had encountered was during setup of Graphite. I had triple-checked that the apache user owned and could write to both my graphite.db and its parent directory. But until I «fixed» SELinux, all I got was a stack trace to the effect of: DatabaseError: attempt to write a readonly database

Community's user avatar

answered Jan 24, 2013 at 3:15

Noah Sussman's user avatar

Noah SussmanNoah Sussman

4,5762 gold badges28 silver badges25 bronze badges

1

This can be caused by SELinux. If you don’t want to disable SELinux completely, you need to set the db directory fcontext to httpd_sys_rw_content_t.

semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/railsapp/db(/.*)?"
restorecon -v /var/www/railsapp/db

answered Dec 13, 2016 at 23:37

Andy Fraley's user avatar

Andy FraleyAndy Fraley

1,0519 silver badges16 bronze badges

In summary, I’ve fixed the problem by putting the database file (* .db) in a subfolder.

  • The subfolder and the database file within it must be a member of the
    www-data group.
  • In the www-data group, you must have the right to write to the
    subfolder and the database file.

####### Additional Notes For Similar Problem #####

I gave write permissions to my sqlite database file to other users and groups but it still didn’t work.

File is in my web root directory for my .NET Core WebApi.

It looked like this:

-rw-rw-rw-  1 root root  24576 Jan 28 16:03 librestore.db

Even if I ran the service as root, I kept getting the error :

Error: SQLite Error 8: ‘attempt to write a readonly database’.

I also did a chown to www-data on the librestore.db and I still received the same error.

Finally I moved up above my webroot directory and gave others write access to that directory (LibreStore — the root of my WebApi) also and then it worked.

Web root has write access

I’m not sure why I had to give the directory write access if the specific file already had write access, but this is the only thing that worked.

But once I made that change www-data user could access the .db file and inserts succeeded.

raddevus's user avatar

raddevus

8,1907 gold badges66 silver badges87 bronze badges

answered Apr 12, 2019 at 14:59

Erkan Hürnalı's user avatar

0

I got this error when I tried to write to a database on an Android system.

Apparently sqlite3 not only needs write permissions to the database file and the containing directory (as @austin-hyde already said in his answer) but also the environment variable TMPDIR has to point to a (possibly writable) directory.

On my Android system I set it to TMPDIR="/data/local/tmp" and now my script runs as expected :)

Edit:

If you can’t set environment variables you can use one of the other methods listed here: https://www.sqlite.org/tempfiles.html#temporary_file_storage_locations
like PRAGMA temp_store_directory = 'directory-name';

answered Apr 3, 2017 at 6:36

Thilo's user avatar

ThiloThilo

2341 silver badge8 bronze badges

0

I got the same error from IIS under windows 7. To fix this error i had to add full control permissions to IUSR account for sqlite database file. You don’t need to change permissions if you use sqlite under webmatrix instead of IIS.

answered Mar 9, 2014 at 18:07

l0pan's user avatar

l0panl0pan

4867 silver badges11 bronze badges

I used:

echo exec(‘whoami’);

to find out who is running the script (say username), and then gave the user permissions to the entire application directory, like:

sudo chown -R :username /var/www/html/myapp

tshepang's user avatar

tshepang

12.1k21 gold badges91 silver badges136 bronze badges

answered Mar 12, 2020 at 9:55

shasi kanth's user avatar

shasi kanthshasi kanth

7,00724 gold badges106 silver badges158 bronze badges

0

(For followers looking for an answer to a similar question)
I’m building a C# .Net Core 6.0 WPF app. I put the Sqlite.db3 on the c:\ drive for convenience while developing. To write to the database I must open Visual Studio 2019 as Administrator.

answered Apr 25, 2021 at 10:15

Ray Brennan's user avatar

Ray BrennanRay Brennan

3731 gold badge6 silver badges19 bronze badges

@Charles in a comment pointed out the solution to this (or at least, a botch solution). This is merely me spelling it out more clearly. Put file_put_contents('./nameofyourdb.sqlite', null); (or .db, whichever you fancy) in a .php file in the root directory of your app (or wherever you want the db to be created), then load that page which renders the php code. Now you have an sqlite db created by whichever user runs your php code, meaning your php code can write to it. Just don’t forget to use sudo when interacting with this db in the console.

A good clean solution to this is to allow the file of your main user account to be written to by (in my case) the http user but this worked for me and its simple.

answered May 31, 2022 at 21:46

a.anev's user avatar

a.aneva.anev

1251 gold badge4 silver badges11 bronze badges

None of these solutions worked for me and I suppose I had a very rare case that can still happen. Had a power shortage so even with 777 permissions on folder and db file, without SELinux, I would get this error.

Turns out there was a jellyfin.pid file (not sure if it’s named after the service or user as they have the same name) locking it after the power shortage. Deleted it, restarted the service and everything worked.

answered Jan 28 at 9:18

NaturalBornCamper's user avatar

Non of above are my cases. It turns out that the container folder is owned by root and has a sticky bits(‘drwxrwxrwt’) and the sqlite db is owned by other user. And the process tries to insert data into table is run under root user. So either of these approach will work:

  • remove sticky bits
  • change the owner user who run the process the same as the owner of the sqlite db file.

answered Jul 13 at 7:13

Dat TT's user avatar

Dat TTDat TT

2,8702 gold badges16 silver badges18 bronze badges

I got this in my browser when I changed from using http://localhost to http://145.900.50.20 (where 145.900.50.20 is my local IP address) and then changed back to localhost — it was necessary to stay with the IP address once I had changed to that once

answered Aug 31, 2016 at 2:08

kris's user avatar

kriskris

11.9k10 gold badges88 silver badges110 bronze badges

I have a SQLite database that I am using for a website. The problem is that when I try to INSERT INTO it, I get a PDOException

SQLSTATE[HY000]: General error: 8 attempt to write a readonly database

I SSH’d into the server and checked permissions, and the database has the permissions

-rw-rw-r--

I’m not that familiar with *nix permissions, but I’m pretty sure this means

  • Not a directory
  • Owner has read/write permissions (that’s me, according to ls -l)
  • Group has read/write permissions
  • Everyone else only has read permissions

I also looked everywhere I knew to using the sqlite3 program, and found nothing relevant.

Because I didn’t know with what permissions PDO is trying to open the database, I did

chmod o+w supplies.db

Now, I get another PDOException:

SQLSTATE[HY000]: General error: 14 unable to open database file

But it ONLY occurs when I try to execute an INSERT query after the database is open.

Any ideas on what is going on?

StayOnTarget's user avatar

StayOnTarget

11.8k10 gold badges52 silver badges84 bronze badges

asked Jul 23, 2010 at 14:31

Austin Hyde's user avatar

Austin HydeAustin Hyde

26.4k28 gold badges96 silver badges129 bronze badges

3

The problem, as it turns out, is that the PDO SQLite driver requires that if you are going to do a write operation (INSERT,UPDATE,DELETE,DROP, etc), then the folder the database resides in must have write permissions, as well as the actual database file.

I found this information in a comment at the very bottom of the PDO SQLite driver manual page.

answered Jul 25, 2010 at 19:08

Austin Hyde's user avatar

Austin HydeAustin Hyde

26.4k28 gold badges96 silver badges129 bronze badges

7

This can happen when the owner of the SQLite file itself is not the same as the user running the script. Similar errors can occur if the entire directory path (meaning each directory along the way) can’t be written to.

Who owns the SQLite file? You?

Who is the script running as? Apache or Nobody?

answered Jul 23, 2010 at 14:35

Charles's user avatar

7

For me the issue was SELinux enforcement rather than permissions. The «read only database» error went away once I disabled enforcement, following the suggestion made by Steve V. in a comment on the accepted answer.

echo 0 >/selinux/enforce

Upon running this command, everything worked as intended (CentOS 6.3).

The specific issue I had encountered was during setup of Graphite. I had triple-checked that the apache user owned and could write to both my graphite.db and its parent directory. But until I «fixed» SELinux, all I got was a stack trace to the effect of: DatabaseError: attempt to write a readonly database

Community's user avatar

answered Jan 24, 2013 at 3:15

Noah Sussman's user avatar

Noah SussmanNoah Sussman

4,5762 gold badges28 silver badges25 bronze badges

1

This can be caused by SELinux. If you don’t want to disable SELinux completely, you need to set the db directory fcontext to httpd_sys_rw_content_t.

semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/railsapp/db(/.*)?"
restorecon -v /var/www/railsapp/db

answered Dec 13, 2016 at 23:37

Andy Fraley's user avatar

Andy FraleyAndy Fraley

1,0519 silver badges16 bronze badges

In summary, I’ve fixed the problem by putting the database file (* .db) in a subfolder.

  • The subfolder and the database file within it must be a member of the
    www-data group.
  • In the www-data group, you must have the right to write to the
    subfolder and the database file.

####### Additional Notes For Similar Problem #####

I gave write permissions to my sqlite database file to other users and groups but it still didn’t work.

File is in my web root directory for my .NET Core WebApi.

It looked like this:

-rw-rw-rw-  1 root root  24576 Jan 28 16:03 librestore.db

Even if I ran the service as root, I kept getting the error :

Error: SQLite Error 8: ‘attempt to write a readonly database’.

I also did a chown to www-data on the librestore.db and I still received the same error.

Finally I moved up above my webroot directory and gave others write access to that directory (LibreStore — the root of my WebApi) also and then it worked.

Web root has write access

I’m not sure why I had to give the directory write access if the specific file already had write access, but this is the only thing that worked.

But once I made that change www-data user could access the .db file and inserts succeeded.

raddevus's user avatar

raddevus

8,1907 gold badges66 silver badges87 bronze badges

answered Apr 12, 2019 at 14:59

Erkan Hürnalı's user avatar

0

I got this error when I tried to write to a database on an Android system.

Apparently sqlite3 not only needs write permissions to the database file and the containing directory (as @austin-hyde already said in his answer) but also the environment variable TMPDIR has to point to a (possibly writable) directory.

On my Android system I set it to TMPDIR="/data/local/tmp" and now my script runs as expected :)

Edit:

If you can’t set environment variables you can use one of the other methods listed here: https://www.sqlite.org/tempfiles.html#temporary_file_storage_locations
like PRAGMA temp_store_directory = 'directory-name';

answered Apr 3, 2017 at 6:36

Thilo's user avatar

ThiloThilo

2341 silver badge8 bronze badges

0

I got the same error from IIS under windows 7. To fix this error i had to add full control permissions to IUSR account for sqlite database file. You don’t need to change permissions if you use sqlite under webmatrix instead of IIS.

answered Mar 9, 2014 at 18:07

l0pan's user avatar

l0panl0pan

4867 silver badges11 bronze badges

I used:

echo exec(‘whoami’);

to find out who is running the script (say username), and then gave the user permissions to the entire application directory, like:

sudo chown -R :username /var/www/html/myapp

tshepang's user avatar

tshepang

12.1k21 gold badges91 silver badges136 bronze badges

answered Mar 12, 2020 at 9:55

shasi kanth's user avatar

shasi kanthshasi kanth

7,00724 gold badges106 silver badges158 bronze badges

0

(For followers looking for an answer to a similar question)
I’m building a C# .Net Core 6.0 WPF app. I put the Sqlite.db3 on the c:\ drive for convenience while developing. To write to the database I must open Visual Studio 2019 as Administrator.

answered Apr 25, 2021 at 10:15

Ray Brennan's user avatar

Ray BrennanRay Brennan

3731 gold badge6 silver badges19 bronze badges

@Charles in a comment pointed out the solution to this (or at least, a botch solution). This is merely me spelling it out more clearly. Put file_put_contents('./nameofyourdb.sqlite', null); (or .db, whichever you fancy) in a .php file in the root directory of your app (or wherever you want the db to be created), then load that page which renders the php code. Now you have an sqlite db created by whichever user runs your php code, meaning your php code can write to it. Just don’t forget to use sudo when interacting with this db in the console.

A good clean solution to this is to allow the file of your main user account to be written to by (in my case) the http user but this worked for me and its simple.

answered May 31, 2022 at 21:46

a.anev's user avatar

a.aneva.anev

1251 gold badge4 silver badges11 bronze badges

None of these solutions worked for me and I suppose I had a very rare case that can still happen. Had a power shortage so even with 777 permissions on folder and db file, without SELinux, I would get this error.

Turns out there was a jellyfin.pid file (not sure if it’s named after the service or user as they have the same name) locking it after the power shortage. Deleted it, restarted the service and everything worked.

answered Jan 28 at 9:18

NaturalBornCamper's user avatar

Non of above are my cases. It turns out that the container folder is owned by root and has a sticky bits(‘drwxrwxrwt’) and the sqlite db is owned by other user. And the process tries to insert data into table is run under root user. So either of these approach will work:

  • remove sticky bits
  • change the owner user who run the process the same as the owner of the sqlite db file.

answered Jul 13 at 7:13

Dat TT's user avatar

Dat TTDat TT

2,8702 gold badges16 silver badges18 bronze badges

I got this in my browser when I changed from using http://localhost to http://145.900.50.20 (where 145.900.50.20 is my local IP address) and then changed back to localhost — it was necessary to stay with the IP address once I had changed to that once

answered Aug 31, 2016 at 2:08

kris's user avatar

kriskris

11.9k10 gold badges88 silver badges110 bronze badges

The «OperationalError: attempt to write a readonly database» error in Python SQLite3 occurs when the script tries to write to a database that has read-only permissions. This error message can occur for various reasons such as insufficient user permissions, the database file being locked by another process, or the file system where the database is stored is read-only. Here are some methods to solve this issue:

Method 1: Changing Permissions

To fix the «python sqlite3 OperationalError: attempt to write a readonly database» error in Python, you can change the permissions of the database file. Here are the steps to do this:

  1. First, check the current permissions of the database file using the ls -l command:
$ ls -l database.db
-r--r--r-- 1 user group 0 Jan 1 00:00 database.db
  1. As you can see, the file has read-only permissions for the owner, group, and others. To change the permissions, use the chmod command:

This will give read and write permissions to the owner and group, and read-only permission to others.

  1. Now, check the new permissions using ls -l:
$ ls -l database.db
-rw-rw-r-- 1 user group 0 Jan 1 00:00 database.db

As you can see, the file now has read and write permissions for the owner and group.

  1. Finally, in your Python code, make sure to open the database file in write mode:
import sqlite3

conn = sqlite3.connect('database.db', mode='w')

This will allow you to write to the database file.

Note: Be careful when changing file permissions, as it can affect the security and stability of your system. Only change permissions when necessary and with caution.

That’s it! With these steps, you should be able to fix the «python sqlite3 OperationalError: attempt to write a readonly database» error by changing the permissions of the database file.

Method 2: Closing Database Connections

To fix the «Python sqlite3 OperationalError: attempt to write a readonly database» error, you can try closing the database connection properly. Here are the steps to do it:

  1. Import the sqlite3 module and connect to the database:
import sqlite3
conn = sqlite3.connect('example.db')
  1. Set the isolation level to None to allow multiple transactions:
conn.isolation_level = None
  1. Create a cursor object to execute SQL statements:
  1. Execute the SQL statement to write to the database:
cur.execute("INSERT INTO table_name (column1, column2) VALUES (?, ?)", (value1, value2))
  1. Commit the changes to the database:
  1. Close the cursor and database connection:

Here is the complete code example:

import sqlite3

conn = sqlite3.connect('example.db')

conn.isolation_level = None

cur = conn.cursor()

cur.execute("INSERT INTO table_name (column1, column2) VALUES (?, ?)", (value1, value2))

conn.commit()

cur.close()
conn.close()

By properly closing the database connection, you should be able to fix the «Python sqlite3 OperationalError: attempt to write a readonly database» error.

Method 3: Moving Database to a Writable Location

One solution to the «Python: how to fix python sqlite3 OperationalError: attempt to write a readonly database?» error is to move the database to a writable location. Here are the steps to do it:

  1. Check the current location of the database file using the os.getcwd() function.
import os
print(os.getcwd())
  1. Create a new directory for the database in a writable location. For example, let’s create a new directory called «db» in the current user’s home directory.
import os
home = os.path.expanduser("~")
db_path = os.path.join(home, "db")
if not os.path.exists(db_path):
    os.makedirs(db_path)
  1. Copy the database file to the new directory.
import shutil
shutil.copy("path/to/database.db", db_path)
  1. Connect to the new database file using the sqlite3.connect() function.
import sqlite3
conn = sqlite3.connect(os.path.join(db_path, "database.db"))
  1. Now you can execute SQL queries on the new database file without getting the «attempt to write a readonly database» error.
cursor = conn.cursor()
cursor.execute("SELECT * FROM my_table")
rows = cursor.fetchall()
for row in rows:
    print(row)

Note that you may need to update your code to use the new database file path instead of the old one.

That’s it! By moving the database to a writable location, you can avoid the «Python: how to fix python sqlite3 OperationalError: attempt to write a readonly database?» error.

У меня есть база данных SQLite, которую я использую для веб-сайта. Проблема в том, что когда я пытаюсь INSERT INTO, я получаю PDOException

SQLSTATE[HY000]: General error: 8 attempt to write a readonly database

I SSH’d на сервер и проверял разрешения, а база данных имеет разрешения

-rw-rw-r--

Я не знаком с разрешениями * nix, но я уверен, что это означает

  • Не каталог
  • У владельца есть права на чтение/запись (что я, согласно ls -l)
  • У группы есть права на чтение/запись.
  • У всех остальных есть разрешения на чтение

Я также искал всюду, что знал, используя программу sqlite3, и не нашел ничего полезного.

Поскольку я не знал, с какими разрешениями PDO пытается открыть базу данных, я сделал

chmod o+w supplies.db

Теперь я получаю еще один PDOException:

SQLSTATE[HY000]: General error: 14 unable to open database file

Но он ТОЛЬКО возникает, когда я пытаюсь выполнить запрос INSERT после открытия базы данных.

Любые идеи о том, что происходит?

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account

Comments

@NearHuscarl

Description

Failed to update sqlite database. Error message says

attempt to write a readonly database

But database object configuration is not (SqfliteDatabaseBase.isOpen = true, SqfliteDatabaseBase.isClosed = false and SqfliteDatabaseBase.readonly = false)

Steps to reproduce

  1. Clone & run this minimal sample (~100 lines)
  2. Click the QUERY and UPDATE button. Open the DEBUG CONSOLE in VSCode, you will see it prints the queried data successfully
  3. Hot restart
  4. Click the QUERY button (Successfully as normal). But clicking the UPDATE button will lead to this error
Exception has occurred.
SqfliteDatabaseException (DatabaseException(attempt to write a readonly database (code 1032 SQLITE_READONLY_DBMOVED[1032])) sql 'UPDATE Test SET phone = ?' args [667136]})

Note: This bug will occur after executing a hot restart, but doing a hot reload or restart completely (Stop and run again) seems to work

Error log

E/SQLiteLog( 7966): (1) fileHasMoved : original inode of /data/user/0/com.example.test_flutter/app_flutter/data.sqlite is (0)
E/SQLiteLog( 7966): (1) Stat of fd(97) : st_mode(100600) st_uid(10235) st_gid(10235) st_ino(329279)
E/SQLiteLog( 7966): (1) File name of fd(97) : /data/data/com.example.test_flutter/app_flutter/data.sqlite (deleted)
E/SQLiteLog( 7966): (1) Stat of /data/user/0/com.example.test_flutter/app_flutter/data.sqlite : st_mode (100600) st_uid (10235) st_gid (10235) st_ino(329473)
E/SQLiteLog( 7966): (1) Stat of /data/user/0/com.example.test_flutter/app_flutter : st_mode(40771) st_uid(10235) st_gid(10235) st_ino(329421)
E/SQLiteLog( 7966): (1) Stat of /data/user/0/com.example.test_flutter : st_mode(40700) st_uid(10235) st_gid(10235) st_ino(329276)
E/SQLiteLog( 7966): (1) Stat of /data/user/0 : st_mode(40771) st_uid(1000) st_gid(1000) st_ino(589826)
E/SQLiteLog( 7966): (1) Stat of /data/user : st_mode(40711) st_uid(1000) st_gid(1000) st_ino(589830)
E/SQLiteLog( 7966): (1) Stat of /data : st_mode(40771) st_uid(1000) st_gid(1000) st_ino(2)
E/SQLiteLog( 7966): (1032) statement aborts at 10: [UPDATE Test SET phone = ?] attempt to write a readonly database
E/flutter ( 7966): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: DatabaseException(attempt to write a readonly database (code 1032 SQLITE_READONLY_DBMOVED[1032])) sql 'UPDATE Test SET phone = ?' args [667136]}
E/flutter ( 7966): #0      wrapDatabaseException 
package:sqflite/src/exception_impl.dart:12
E/flutter ( 7966): <asynchronous suspension>
E/flutter ( 7966): #1      SqfliteDatabaseFactoryImpl.wrapDatabaseException 
package:sqflite/src/factory_impl.dart:25
E/flutter ( 7966): #2      SqfliteDatabaseMixin.safeInvokeMethod 
package:sqflite/src/database_mixin.dart:188
E/flutter ( 7966): #3      SqfliteDatabaseMixin.txnRawUpdate.<anonymous closure> 
package:sqflite/src/database_mixin.dart:388
E/flutter ( 7966): #4      SqfliteDatabaseMixin.txnSynchronized.<anonymous closure> 
package:sqflite/src/database_mixin.dart:307
E/flutter ( 7966): #5      BasicLock.synchronized 
package:synchronized/src/basic_lock.dart:31
E/flutter ( 7966): #6      SqfliteDatabaseMixin.txnSynchronized 
package:sqflite/src/database_mixin.dart:303
E/flutter ( 7966): #7      SqfliteDatabaseMixin.txnWriteSynchronized 
package:sqflite/src/database_mixin.dart:325
E/flutter ( 7966): #8      SqfliteDatabaseMixin.txnRawUpdate 
package:sqflite/src/database_mixin.dart:387
E/flutter ( 7966): #9      SqfliteDatabaseExecutorMixin.rawUpdate 
package:sqflite/src/database_mixin.dart:128
E/flutter ( 7966): #10     SqfliteDatabaseExecutorMixin.update 
package:sqflite/src/database_mixin.dart:153
E/flutter ( 7966): #11     _SqfliteAttemptToWriteInReadonlyDatabaseState.build.<anonymous closure> 
package:test_flutter/src/sqflite_attempt_to_write_in_readonly_database.dart:95
E/flutter ( 7966): <asynchronous suspension>
E/flutter ( 7966): #12     _InkResponseState._handleTap 
package:flutter/…/material/ink_well.dart:706
E/flutter ( 7966): #13     _InkResponseState.build.<anonymous closure> 
package:flutter/…/material/ink_well.dart:789
E/flutter ( 7966): #14     GestureRecognizer.invokeCallback 
package:flutter/…/gestures/recognizer.dart:182
E/flutter ( 7966): #15     TapGestureRecognizer.handleTapUp 
package:flutter/…/gestures/tap.dart:486
E/flutter ( 7966): #16     BaseTapGestureRecognizer._checkUp 
package:flutter/…/gestures/tap.dart:264
E/flutter ( 7966): #17     BaseTapGestureRecognizer.handlePrimaryPointer 
package:flutter/…/gestures/tap.dart:199
E/flutter ( 7966): #18     PrimaryPointerGestureRecognizer.handleEvent 
package:flutter/…/gestures/recognizer.dart:467
E/flutter ( 7966): #19     PointerRouter._dispatch 
package:flutter/…/gestures/pointer_router.dart:76
E/flutter ( 7966): #20     PointerRouter._dispatchEventToRoutes.<anonymous closure> 
package:flutter/…/gestures/pointer_router.dart:117
E/flutter ( 7966): #21     _LinkedHashMapMixin.forEach  (dart:collection-patch/compact_hash.dart:379:8)
E/flutter ( 7966): #22     PointerRouter._dispatchEventToRoutes 
package:flutter/…/gestures/pointer_router.dart:115
E/flutter ( 7966): #23     PointerRouter.route 
package:flutter/…/gestures/pointer_router.dart:101
E/flutter ( 7966): #24     GestureBinding.handleEvent 
package:flutter/…/gestures/binding.dart:218
E/flutter ( 7966): #25     GestureBinding.dispatchEvent 
package:flutter/…/gestures/binding.dart:198
E/flutter ( 7966): #26     GestureBinding._handlePointerEvent 
package:flutter/…/gestures/binding.dart:156
E/flutter ( 7966): #27     GestureBinding._flushPointerEventQueue 
package:flutter/…/gestures/binding.dart:102
E/flutter ( 7966): #28     GestureBinding._handlePointerDataPacket 
package:flutter/…/gestures/binding.dart:86
E/flutter ( 7966): #29     _rootRunUnary  (dart:async/zone.dart:1138:13)
E/flutter ( 7966): #30     _CustomZone.runUnary  (dart:async/zone.dart:1031:19)
E/flutter ( 7966): #31     _CustomZone.runUnaryGuarded  (dart:async/zone.dart:933:7)
E/flutter ( 7966): #32     _invoke1  (dart:ui/hooks.dart:273:10)
E/flutter ( 7966): #33     _dispatchPointerDataPacket  (dart:ui/hooks.dart:182:5)

Information

  • OS: Window 10
  • IDE: VSCode
  • Device: Galaxy A10
  • Flutter version
$ flutter --version
Flutter 1.13.0 • channel dev • https://github.com/flutter/flutter.git
Framework • revision 09126abb22 (2 days ago) • 2019-12-03 17:43:00 -0800
Engine • revision 6179380243
Tools • Dart 2.7.0 (build 2.7.0-dev.2.1 a4d799c402)

@alextekartik

The issue is about hot restart and deleting the database here. The current workaround is to open the database and close it before deleting it.

Maybe deleteDatabase (instead of calling File().delete) should do the proper cleanup but it is not the case neither. Since many are running into this, I guess I should fix deleteDatabase behavior (well that is not really a fix, it is a hotload issue where the db is not closed on hotrestart).

I will work on it.

@alextekartik

As of sqflite 1.1.8, the behavior of deleteDatabase has slightly change, for the better hopefully as I don’t consider this a breaking change.

It now supports Android restart and hot restart in general. If the database was opened previously as a single instance, the database is closed first, then deleted.

This means that the trick of opening the database before deletion is no longer needed.

@caseyryan

The bug is still present. I couldn’t find where the deleteDatabase() method is

Понравилась статья? Поделить с друзьями:
  • Ошибка atomizer short как исправить
  • Ошибка atikmpag sys windows 10 как исправить
  • Ошибка atibtmon exe windows 7
  • Ошибка atiadlxx dll
  • Ошибка apt fix broken install