Expected 'tables' during Flyway migration - questdb

I'm moving over to QuestDB using the postgres connection and my flyway migration fails with a FlywaySqlException. I can see this in the logs:
SQL State : null
Error Code : 0
Message : ERROR: expected 'tables' or 'columns'
...
Caused by: org.postgresql.util.PSQLException: ERROR: expected 'tables' or 'columns'

The problem you are hitting is that the CREATE keyword expects table, so you will get this if your flyway migration query is using
--will break
CREATE DATABASE <db_name>
Multiple databases are not supported by QuestDB as of yet, so default postgres configuration is:
database: qdb
Instead of creating multiple DBs, you can separate data out into multiple tables.

Related

I did Migration process and I didn't get error but I am missing my database and table in sql. VS not transferring the data to sql

Hi I am the beginner developer, I am trying to send my data to sql from VS and I did Migration process. in packing manager console I wrote enable-migration and now I got configuration file also and after than I changed the value from false to true and wrote update-database I am not getting error its just says
PM> update-database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
No pending explicit migrations.
Running Seed method.
and when I checked sql there is no my database also any tables
I am trying to make travel website and there are some page exist and I got some models files of them and I guess I need to create connection between sql and vs I had the code in vstudio but when I try to create database and tables with my datas in studio, its not happening

If Operational error happens in django query in read database router, rerun the query on write database

When a read query from read_db() router fails due to following error
ERROR: cancelling statement due to conflict with recovery
Detail: User query might have needed to see row versions that must be removed
how to catch the error and retry the same query on a write db.
Please note, this is not a Django problem, but PostgreSQL.
Two solutions are:
hot_standby_feedback OR
max_standby_archive_delay
See docs:
https://www.postgresql.org/docs/current/runtime-config-replication.html

Django tests failing to run because they can't create table due to malformed foreign key

When attempting to run my tests, I get the error in the title. It does not tell me anything remotely useful about which table has failed to be created because the raw output of the error is: django.db.utils.OperationalError: (1005, 'Can\'t create table `test_pogo`.`#sql-269_231` (errno: 150 "Foreign key constraint is incorrectly formed")')
#sql-269_231 gives me absolutely no information as to where I should go and check in my models to find the error, as it is not the name of any of my models or database tables.
When running the project (not the testing modules) locally with my prod copy, everything seems to work as expected.
How do I find and fix the broken model?

relation "django_session" does not exist - django, heroku

I deployed my app on Heroku, I can see it perfectly from the local server where the website works. The problem is that whenever I try to enter as the admin within the Heroku website (https://awayfromspain.herokuapp.com/admin/) I got the following error:
ProgrammingError at /admin/
relation "django_session" does not exist
LINE 1: ...ession_data", "django_session"."expire_date" FROM "django_se...
I also get this when I try to enter in the pages that are related to my models:
column myapp_experience.slug does not exist
LINE 1: ...p_experience"."title", "myapp_experience"."text", "myapp_exp...
I think I have problems with the database... but I tried to flush and I get:
Running python manage.py flush on ⬢ awayfromspain... up, run.2445 (Free)
You have requested a flush of the database.
This will IRREVERSIBLY DESTROY all data currently in the 'df1neimk7ipkd5' database,
and return each table to an empty state.
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
CommandError: Database df1neimk7ipkd5 couldn't be flushed. Possible reasons:
* The database isn't running or isn't configured correctly.
* At least one of the expected database tables doesn't exist.
* The SQL was invalid.
Hint: Look at the output of 'django-admin sqlflush'. That's the SQL this command wasn't able to run.
The full error: cannot truncate a table referenced in a foreign key constraint
DETAIL: Table "myapp_franceexperience" references "auth_user".
HINT: Truncate table "myapp_franceexperience" at the same time, or use TRUNCATE ... CASCADE.
Where franceexperience was a model that I deleted. How should I proceed? I applied migrations.
Thanks in advance !
Your migrations have obviously got out of sync; franceexperience should have been deleted when you removed the model.
You should makemigrations again locally and check that it adds a migration to delete that table. Then commit your code, push it, and do heroku run ./manage.py migrate; this should remove the deleted table but also hopefully add the missing session table.

Using .annotate() in django migrate

I've encountered a very strange bug. I have a django migration that runs this query:
venues = Venue.objects.annotate(num_activities=Count('activities'))\
.filter(num_activities=1, activities__activity__code="GOLF", timings=None)\
.all()
The query itself works when the database is already up to date, but when initialising the database from scratch (running all migrations from 0001_initial), I get the error:
*** django.core.exceptions.FieldError: Cannot resolve keyword 'activities' into field.
So that migration fails. But if I run it again, with the database now in a partially migrated state (i.e. going only from 0065 -> 0066), it works just fine.
Any ideas about why it wouldn't work when running from scratch? Is there a bug in the django migration script? Seems to be due to the .annotate() function.