AWS Django Elastic Beanstalk migration error - mysql

Background
I created a website using Django and have it deployed on AWS EB with a MySQL Amazon RDS database. Recently I added a new field to one of the existing models in my models.py file. Everything worked fine on my local server (uses local SQLite, not RDS), but when I deployed the new update to EB I get the following error when I visit any page:
OperationalError at /
(1054, "Unknown column 'old_model.new_field' in 'field list'")
Question
What did I do wrong to get the error above and what can I do to fix it?
db-migrate.config:
container_commands:
01_migrate:
command: "django-admin.py migrate"
leader_only: true
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: app.settings

Creating a manual migration with python manage.py makemigrations, if this doesn't found any new changes in models try the same with your app name and then migrate the DB with python manage.py migrate
This should solve your issue. if this doesn't solve your issue, clear all the migrations file the again run makemigrations

I suspect migrations are not running properly.
Create an EC2 instance and try to run migrations on it connected to RDS instead of local sqlite DB.
Make sure your EC2 instance and RDS are on the same VPC.
After that deploy your app to EB.

Related

Laravel: No such file or directory for table in AWS RDS laravel

I currently deployed my laravel app to the AWS elastic beanstalk. I created RDS mysql database. I imported my sql dump from my local project and deployed it to the AWS EC2 server. But I'm getting this error.
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from settings where code = company-name limit 1).
Is there any way how to check if there are data in my DB ? Just to note I'm still learning moving around AWS. Thanks.
EDIT :
I'm also getting correct Environment & details like RDS_PORT RDS_HOST... , on error page where I can see the error displaying
You can follow this tutorial to connect to a MYSQL RDS Database on AWS.
So you can check if all your tables have been created successfully.
AWS Connect to Database Tutorial
Make sure that you open the port of the RDS database in the security group. Otherwise your local machine can't connect to the Database.

MySQL Test DB Failing

I set up a Django 2 app (and Python 3.6) with a remote MySQL DB (using mysqlclient), with proper permissions.
When I run my unit test, I get the following error: django.db.utils.ProgrammingError: (1146, “Table ‘test_<db>.<db>’ doesn’t exist”).
When I manually open the website at localhost, everything works fine.
Technically I could create a local dev DB for testing, but I would prefer that the test DB is created automatically.
EDIT
It seems like the issue was related to my tables not being managed by Django, see here.
I believe this is a duplicate.
Django : Table doesn't exist
If the table is missing, make sure you've got the right migration file (python manage.py makemigrations) and that you've applied it (python manage.py migrate).
What worked for me:
Changing my tables to managed = True.
Deleting migration files (except __init__.py).
python manage.py makemigrations
python manage.py migrate
And now my unit tests are running.

could not find driver SQL but migrate works

I deployed my code to server and migrated the database with command bellow:
php artisan migrate
And everything works fine.
But when I want to access to my url it throws the following exception:
could not find driver (SQL: select * from `...`)
If it cannot find the driver then how it created the tables? Am I missing something.
Also my database works fine when I run
php artisan serve
on my server and access that locally.

Regenerate YML mapping issue in Symfony 2.4

Running a Symfony 2 project, I have recently made a change in my MYSQL database, and I would like to update my schema and model structure inside my symfony project so I can use the new items that are in it.
This is what I try to do from a running instance in production:
php app/console doctrine:mapping:import --force CoreBundle yml
Here is the error I get:
[PDOException] SQLSTATE[HY000] [2002] Connection timed out
Core/Bundle exists and was already mapped this way by the past
Also note that the server is up and running, doing exchanges with the database
I cannot find a place where to see a more detailed log. Tried to configure the config.yml to add logging for doctrine but it doesn't give me more infos
Thanks in advance
Since I didn't found the source of the problem, I just deployed a new symfony app, connected it to the database and then just generated orm + entities by following the same commands. After that I just copied the /Entity folder and /orm folder and replaced it on my production env. A bit messy but it worked

rake db:migrate runs in development AWS Beanstalk

I'm new to Beanstalk. I've created a Rails application and set the database production configuration to use the environment variables hopefully provided by AWS. I'm using Mysql (mysql2 gem), and want to use RDS and Passenger (I have no preference there).
On my development environment I can run the rails application with my local Mysql (it is just a basic application I've created for experimentation).
I have added the passenger gem to Gemfile and bundled, but I'm using WEBBrick in development still.
The only thing I did not do by the book is that I did not use 'eb' but rather tried from the console. My application/environment failed to run as while "rake db:migrate" it still thinks I wanted it to connect to the local Mysql (I guess from the logs that it is not aware of RACK_ENV and hence uses 'development').
Any tip? I can of course try next the 'eb', yet would prefer to work with the console.
Regards,
Oren
In Elastic Beanstalk (both the web console and the cli), you can pass environnement variables. If you pass the RAKE_ENV variable, you will change your environnement.
After that you still need to pass your database parameters (db password, name, ...) which should not be hardcoded into the code.
Have you tried to run
bin/rake db:migrate RAILS_ENV=development
?
I got the same issue and that worked for me.
I recommend you enter to EC2 instance through this command "eb ssh" (The first time you need specified you .pem file, if you have not one you can create in IAM services) and check your logs for more information about yours error.
If you have problems when you are uploading your code (eb deploy) you have the log in this file: "/var/log/eb-activity.log" (Remember this file is in your EC2 instance)
If you have a problems with your app, you can read the logs in this files: "/var/app/support/logs/production.log" or "/var/app/support/logs/passenger.log"
Other recommedations is install EB CLI version 3. for manage your eb instance
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html
I believed that Elastic Beanstalk will run 'rake db:migrate' by itself. Indeed it seems to try, but that is failing. I gave my bounty to 'Yahs Hef', even though I will only try this evening (UK). My disorientation with AWS caused me to forget this easy solution, of running the migration by myself. If this does not work by itself, I'll simplify the database configuration as possibile.