As you’re working on your website, you’ll likely need to upload new files. During this process, WordPress may generate an error saying that it “could not insert attachment into the database”. In this case, any uploaded images or posts won’t be added to your website.
Fortunately, there are many ways to fix the “WordPress could not insert attachment into the database” error. By simply resizing images or updating file names, you could meet WordPress’s requirements for new uploads. However, you may need more extensive solutions, like increasing your site’s memory limit.
In this post, we’ll explain what the “WordPress could not insert attachment into the database” error is. Then, we’ll show you eight different ways to fix this problem. Let’s get started!
What Is the “WordPress Could Not Insert Attachment Into the Database” Error?
An important part of designing a website is uploading images. Whether you find free photos online or create custom graphics, you can add them to the WordPress Media Library. This will store all your media files and enable you to insert them into pages or posts:
Additionally, you may have to add other types of files to WordPress. If everything is working properly, you should be able to upload files like documents, audio, or videos in a post, page, or the Media Library:
However, you may run into an error when uploading new images or other files. This will display a message that “WordPress could not insert attachment into the database”. Although this mainly happens with uploaded files, it can also prevent you from publishing new posts.
In most cases, this error happens when your server can’t support the amount of resources you’re trying to use. If you have a shared hosting plan, these problems could also result from another website receiving unexpectedly high traffic.
Here are some other potential causes for the “WordPress could not insert attachment into the database” error:
- PHP memory has been exhausted
- File names have special characters
- Plugin or theme conflicts
- Incorrect file permissions
When you see this error, you won’t be able to use files on your website. To continue customizing your pages and posts, you’ll need to resolve the problem and try reuploading the file.
How To Fix the “WordPress Could Not Insert Attachment Into the Database” Error (8 Methods)
The “WordPress could not insert attachment into the database” error can stop you from uploading new files to your website. Since media is an important part of web design, you’ll need to know how to fix this problem.
Without further ado, here’s how to resolve this image upload issue in WordPress!
1. Resize the Image
When you upload new images to WordPress, this takes up space on your server. If these images are too large, you could overload your server’s allocated resources. Plus, it may increase your page loading time.
If you receive the “could not insert attachment into the database” error, you might be exceeding the maximum upload size. Depending on your WordPress hosting provider, this typically falls between 4 and 128 MB.
For the typical WordPress user, you’ll likely never exceed this limit. However, media-heavy websites like photography portfolios might experience upload errors.
In this case, you can try adjusting your image sizes. Generally, the largest size in WordPress is 1024px. It’s best to avoid uploading any images bigger than this.
Additionally, it’s important to compress all your images. Although WordPress automatically applies image compression, this may not be enough to significantly reduce the file size.
To ensure you’re not overloading your server, you can use a compression plugin like EWWW Image Optimizer. This tool automatically compresses, resizes, and rescales images, so they’re optimized for WordPress:
Plus, EWWW Image Optimizer can perform both lossless and lossy compression on your images. If image file sizes are causing the “WordPress could not insert attachment into the database” error, applying the right compression could solve the issue.
2. Change the File Name
Resolving the “WordPress could not insert attachment into the database” error could be as simple as a file name change. Based on how your database was configured, it may have character sets or collations that prevent certain file names.
If you see the “could not insert attachment into the database” error, WordPress wasn’t able to input your uploaded file into the MySQL database. Its default settings may not allow special characters.
To fix the issue, try renaming the file. Make sure to remove any unnecessary symbols or punctuation marks. It’s best to use words separated by dashes or underscores instead:
Once you do this, try to reupload the file. If it’s still unsuccessful, move on to the next method!
3. Deactivate Conflicting Plugins and Themes
Since WordPress is an open-source platform, third-party developers can sell their own themes and plugins for you to use. Some of these tools may be poorly coded, causing conflicts with other software on your site.
Whenever an error occurs in WordPress, it’s a good idea to evaluate whether it came from a plugin or theme conflict. To get started, you’ll need to temporarily deactivate your plugins.
Simply select the ones that are currently active, then choose Deactivate in the Bulk Actions menu:
Next, try to upload the file again. If it works, then one of your plugins was causing the problem.
Now, reactivate your plugins one by one and try uploading a file after each reactivation. This will help you find out which plugin is triggering the “could not insert attachment into the database” error.
Once you find the culprit, you may want to remove it from your site or contact its developer to tell them about the issue.
It’s also possible for your theme to cause conflicts. You can quickly check to see if this is the case by activating a default WordPress theme like Twenty Twenty-Three:
If this resolves the error, you’ll likely need to use a different theme. However, your file upload problems could result from an entirely different issue. In that case, it’s time to troubleshoot your database.
4. Check Your Database Size
When an image won’t upload to WordPress, there might not be enough server resources to support the file. To see if this is the case, you can check your database size. This will tell you how much disk space your images, videos, and other files are consuming
Once you log into your account, click on the WordPress Sites tab. Then, look in the Disk Usage column:
Your resource usage will also be in the Analytics section for a specific site. Go to Resources > Disk space to see your storage limit and current usage:
You can also view this information directly in the dashboard. Under Resource usage, click on the Learn more button next to Disk usage:
In the pop-up, you’ll see a breakdown of your disk usage. It will show your total allowed space, along with the current sizes of your files and databases:
If you use another web host, you can track this information in your WordPress dashboard. Go to Tools > Site Health > Info and find Directories and Sizes.
This will show your database sizes, as well as information about your different directories:
If your disk space usage is close to the limit set by your hosting provider, you’ll likely need to upgrade to a higher plan. Alternatively, Kinsta users can install the Disk Space add-on. This will increase your storage without having to switch plans.
5. Increase Your PHP Memory Limit
To store your files, your website needs to have memory. When you select a hosting plan, your host will determine your site’s PHP memory limit. At Kinsta, we set this limit at 256 MB.
As your website grows, you’ll need to add new files, plugins, themes, and even custom code. This means that you’ll be using a higher level of memory. If you exceed your limit, WordPress won’t have enough memory to store new files, which can cause the “WordPress could not insert attachment into the database” error.
Then, open a File Transfer Protocol (FTP) client like FileZilla. This will enable you to access and edit your site’s files:
To use FileZilla, you’ll need your SFTP login credentials. In MyKinsta, navigate to Sites > Info. Under SFTP/SSH, copy your hostname, username, password, and port number:
Now, return to FileZilla and open the Site Manager. Select SFTP – SSH File Transfer Protocol, enter your login credentials, and hit Connect:
Once you’ve connected to your site, find the Remote site box. Here, you’ll see a directory with your site files.
To edit your memory limit, open the public folder and find the wp-config.php file:
Right-click on the file and select View/Edit to open it in a text editor. Then, find this line of code:
define( ‘WP_MEMORY_LIMIT’, ‘256M’ );
If your memory limit is less than 256MB, you’ll likely need to add a higher number. When you’re ready, save the file and try uploading an image to your site.
6. Turn on WordPress Debug Mode
Another way to find the source of the “WordPress could not insert attachment into the database” error is to enable the debug mode in WordPress. WP Debug can help you flag PHP errors and other warnings, so you don’t have to search through the code yourself.
Although you can install a debugging plugin or manually enable this process in WordPress, we created an easier way to do this. In MyKinsta, open the Tools tab within your site’s dashboard.
Then, find and enable the WordPress debugging option:
When you log in to your WordPress dashboard, you’ll receive new alerts about errors on your site. These will tell you exactly what caused the problem, so you’ll know how to fix it.
Once you find the source of the “WordPress could not insert attachment into the database” error, make sure to disable WordPress debugging. Since it could display PHP code to front-end visitors, leaving it enabled could compromise your site’s security.
7. Update the File Permissions
If you’re still struggling to identify how to fix this image upload issue in WordPress, you may need to update your file permissions. These restrict file access to specific users. If your file permissions are configured incorrectly, you won’t be able to upload new files onto the server.
To fix this problem, you’ll need to reconnect to your SFTP client. Then, navigate to public > wp-content, right-click on the uploads file, and hit File Permissions:
This will pull up information about your current permissions. You’ll see three different user groups: owner, group, and public. You can control which of these users can read, write, and execute your WordPress files:
Your file permissions are represented by a permission code. Here’s what that means:
- First digit: specifies file permissions for the owner
- Second digit: specifies file permissions for the group users
- The third digit: specifies file permissions for the public
For the uploads file, make sure the file permissions are set at ‘744.’ Then, select Apply to directories only:
After you save these changes, reopen the file permissions. This time, you’ll need to reset the permissions for all the files in this directory.
To do this, set the numeric value at ‘644’. You’ll also need to select Recurse into subdirectories and Apply to files only:
Updating file permissions for uploads
Now, try re-uploading your WordPress files! If these new permissions don’t solve the problem, try setting the directories to ‘755’ instead.
8. Contact Your Hosting Provider
Even after extensive troubleshooting, you may still be unable to solve the “WordPress could not insert attachment into the database” error. If all else fails, you can contact your hosting provider for help.
Our support staff at Kinsta offers 24/7 customer service. No matter which hosting plan you’re using, you’ll have unrestricted access to chat support.
In your MyKinsta dashboard, click on the chat option in the lower right corner. Then, send a message to one of our team members:
By talking with our WordPress professionals, you can solve WordPress errors in no time!
Certain WordPress errors can prevent you from adding content to your site. When you see a “WordPress could not insert attachment into the database” message, you won’t be able to upload files or publish new posts.
To get WordPress functioning normally again, you can simply try waiting a few minutes before reuploading the file. If it wasn’t a temporary error, check for plugin conflicts, increase your PHP memory limit, or turn on WordPress debugging.
At Kinsta, we know how frustrating it can be to troubleshoot WordPress errors. When you sign up for our WordPress hosting plans, our experts will be available 24/7 to help you fix any problem you experience!