What can be done to fix the "WordPress could not insert attachment into the Database" Error - (r)

Jan 9, 2023
Figuring out why wordpress could not insert attachment into the database

When you're developing your website, you'll probably need to upload new files. During this process, WordPress may generate an error that says that it "could not create attachments in the database". This means that any posted images or content uploaded won't be displayed on your website.

There are several ways to fix the "WordPress cannot insert the attachment into the database" error. Simply resizing images, or changing file names to be able to meet WordPress's standards to upload new files. However, you may need more extensive solutions, like increasing your site's memory limit.

In this article, we'll explain what the "WordPress couldn't insert the attachments into database" error means. We'll then show eight different ways to fix this problem. Let's get started!

What is the "WordPress Cannot Insert attachments into the Database" Error?

The WordPress Media Library
WordPress Media Library
Uploading files to WordPress
Upload your files to WordPress

Below are additional possible causes for the "WordPress couldn't insert an attachments into your database" error:

  • File names have special characters
  • Theme or plugin conflicts

If you encounter this error message, you'll not be able to use images on your site. If you want to continue customizing your webpages and posts, you'll need solve the issue, and then try to upload the file again.

What can be done to fix the "WordPress Could Not Insert Attachment Into the Database" Error (8 Methods)

Without further ado this is how you can fix the issue of uploading images in WordPress!

1. Resize the image

If you're a typical WordPress users, you'll probably never exceed this limit. On the other hand, sites with heavy media content such as portfolios of photography may encounter upload problems.

It is also important to reduce the size of all your photos. Even though WordPress uses automatic compression to images but this might not be enough to significantly shrink the size of the image.

In order to ensure that you're not overloaded your server, you can make use of a compression tool like ShortPixel. The tool compresses, resizes, and scales images to ensure they're optimized to work with WordPress:

ShortPixel plugin
ShortPixel

2. Modify the File Name

Resolving the "WordPress couldn't insert the attachment into the database" problem can be as easy as a file name change. Based on the way your database was setup it could have character sets or collations which prevent specific file names.

For a solution Try renaming the file. Be sure to eliminate any unnecessary symbols or punctuation marks. The best way to write your words is to use them separated by dashes or underscores instead:

Searching for image file names
Image file names

Once you do this then try re-uploading the file. If it's still unsuccessful then move to the next option!

3. Remove conflicting plugins and themes

As WordPress is an open source platform, developers from third parties can offer their own themes and plugins for you to use. Certain of these plugins may be poorly coded, causing conflict with other software that is on your site.

Simply select the ones that are at present active, and click Deactivate in the Bulk Actions menu:

WordPress plugins page in the dashboard
Deactivate the entire WordPress plugins. WordPress plugins

Next, try to upload the file again. If it works, then the plugin you are using was at fault.

Then, restart your plugins in one at a time and attempt to upload a file following every restart. It will allow you to figure out which plugin causes the "could not add attachment to your database" error.

If you discover the source of the problem, you may want to delete it from your site or contact the developer of the site to inform them about the issue.

If that fixes the issue, you'll likely need to use a different theme. But, the file upload problems could result from another issue. In that case, it's time to solve the problem with your database.

4. Check Your Database Size

When you have logged to your account, click on the WordPress Sites button. Then, look in the disk usage column:

Disk usage in the My dashboard
The use of disks within My

Your resource usage will also be in your Analytics area for the specific website. Click on the Resources tab and select Disk space to view your storage limit and actual usage

 disk space usage and limit
Use of disk space as well as limit

You can also view these data directly on the dashboard. Under Resource use Click on the "Learn more" option under the Disk utilization:

Disk usage numbers inside My
disk usage

The pop-up will allow you to see a overview of the disk's usage. It will show your space allowance and the actual size of your databases and files: databases:

Want to know the ways we have increased traffic over 1000 percent?

Join the 20,000+ who receive our newsletter every week with insider WordPress tips!

 resource usage breakdown
Utilization breakdown of resources

If you're using another hosting provider, you are able to track the information on the WordPress dashboard. Go to Tools > Site Health > Information and look for Directories and Sizes.

This will show the size of your databases, as well as information about your different directories:

WordPress directories and sizes
The size of the directory on WordPress Site Health

5. The PHP memory limit can be increased.

If your website expands, you'll need to add more files, plugins and themes, or even your own software. It means that you'll use a greater level of memory. If you're over the limit, WordPress won't have enough storage space to hold the new files. This could create the "WordPress could not insert files into databases" error.

Download
FileZilla
My SFTP login credentials
My SFTP login credentials

Return to FileZilla and open FileZilla's Site Manager. Click SSH File Transfer Protocol to open the SSH to connect. Select File Transfer Protocol, enter your login credentials and press Connect:

Connect website in FileZilla
Connect website on FileZilla

Once you've connected to your website, look for the Remote website box. In this box, you'll be able to see a directory with your site data.

To modify your memory limit, open the public folder and locate the wp-config.php file:

Editing the wp-config.php file
Editing the wp-config.php file

Click on the file with the right-click and choose View/Edit to open it in a text editor. Then, find this line of code:

  define( 'WP_MEMORY_LIMIT', '256M' );  

If your memory limits are lower than 256MB, then you'll likely need to add a higher number. When you're ready to save your file, try uploading an image to your site.

6. Switch on WordPress Debug Mode

After that, you can allow the WordPress debugging option:

WordPress Debugging in My
WordPress Issues in My

When you log in to your WordPress account, you'll be notified of new alerts about errors on your site. These will tell you exactly what caused the problem and the best way to correct it.

If you can pinpoint the cause of the "WordPress could not insert attachments into database" error, ensure you disable WordPress debugging. As it may display PHP codes to visitors on the front end, leaving it enabled could compromise your site's security.

7. Change the permissions for Files.

To fix this problem the first step is to reconnect with you SFTP client. Then, navigate to public > wp content, right-click on uploads, right-click on uploads fileand then click the File Permissions button.:

Editing file permissions for WordPress uploads
Editing file permissions for WordPress uploads
Changing file permissions
Modifying permissions on files

The permissions of your file are described by a permission code. This is what it means:

  • The first digit indicates permissions to file to the file's owner
  • Second Digit indicates the file permissions for the group of users
  • The third digit: specifies file permissions for the public

To upload your uploads files, ensure that permissions for the file are set at '744.' Then, select Apply to directories only:

Updating uploads directory permissions
Uploads that are updated and directory permissions changed

After you save these changes and then reopen the permissions for the file. This time, you'll need reset permissions for all the files in this directory.

In order to do that, change the numeric value to '644'. It is also necessary to select Recurse in subdirectories and Apply to files only:

  Permissions of files to update for uploads  

Now, try re-uploading your WordPress file! If the new permissions do not resolve the issue, you can consider setting the directories to '755' instead.

8. Contact Your Hosting Provider

Even after extensive troubleshooting, you may still be unable to resolve the "WordPress cannot insert the attachments into databases" error. If nothing else works it is possible to ask your hosting service provider for assistance.

On your dashboard, go to the chat button in the lower right corner. Then, send a message to any member of the team:

Get support right in My
My assistance

By talking with our WordPress specialists, you'll be able to find the root of WordPress errors in no time!

Summary

Certain WordPress issues can stop the addition of content on your site. When you see an "WordPress could not insert attachment into the database" message, you won't be able upload any files or create new content.

  • Simple setup and management on the My dashboard
  • 24/7 expert support
  • The most efficient Google Cloud Platform hardware and network, that is powered by Kubernetes for maximum scalability
  • A high-end Cloudflare integration to speed up and security
  • Global audience reach with more than 35 data centers and more than 275 PoPs in the world.