not-exists

Django migration dependencies reference nonexistent parent node

霸气de小男生 提交于 2019-12-02 04:59:11
I have a problem with django migrations. I get this error: django.db.migrations.exceptions.NodeNotFoundError: Migration user.0050_merge_20170523_1254 dependencies reference nonexistent parent node ('user', '0049_auto_20170519_1934') I fix the errors, deleting some lines but after fix all this errors, I get other: ValueError: Could not find common ancestor of {'0050_merge_20170523_1254', '0007_auto_20170524_1540'} I cant solve that. I can drop database and do makemigrations again... but in production environment I want know how fix correctly, without drop database haha. Thanks! Next time when

mysql: select all items from table A if not exist in table B

青春壹個敷衍的年華 提交于 2019-11-29 05:53:53
I am having problem with selecting values from table a (id, room_name) where there are no corresponding events in table b (room_id, room_start, room_finish) my query looks following SELECT id, room_name FROM rooms WHERE NOT EXISTS (SELECT * FROM room_events WHERE room_start BETWEEN '1294727400' AND '1294729200' OR room_finish BETWEEN '1294727400' AND '1294729200') table a contains multiple rooms, table b contains room events I am getting no results in case there is any event for any of the rooms within the timestamps. I am expecting all rooms having NO events. Here is the prototype for what

How can I do an insert where not exists?

最后都变了- 提交于 2019-11-29 01:20:59
I'd like to combine an insert query with a "where not exists" so as not to violate PK constraints. However, syntax such as the following gives me an Incorrect syntax near the keyword 'WHERE' error - INSERT INTO myTable(columns...) VALUES(values...) WHERE NOT EXISTS (SELECT * FROM myTable WHERE pk_part1 = value1, AND pk_part2 = value2) How can I accomplish this? (In general, can you combine an insert with a where clause?) INSERT INTO myTable(columns...) Select values... WHERE NOT EXISTS (SELECT * FROM myTable WHERE pk_part1 = value1, AND pk_part2 = value2) Edit: After reading martins link, If

Add a column to a table, if it does not already exist

我与影子孤独终老i 提交于 2019-11-28 04:26:13
I want to write a query for MS SQL Server that adds a column into a table. But I don't want any error display, when I run/execute the following query. I am using this sort of query to add a table ... IF EXISTS ( SELECT * FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'[dbo].[Person]') AND TYPE IN (N'U') ) But I don't know how to write this query for a column. Lieven Keersmaekers You can use a similar construct by using the sys.columns table io sys.objects . IF NOT EXISTS ( SELECT * FROM sys.columns WHERE object_id = OBJECT_ID(N'[dbo].[Person]') AND name = 'ColumnName' ) SPL IF COL_LENGTH('table

mysql: select all items from table A if not exist in table B

假装没事ソ 提交于 2019-11-27 23:43:57
问题 I am having problem with selecting values from table a (id, room_name) where there are no corresponding events in table b (room_id, room_start, room_finish) my query looks following SELECT id, room_name FROM rooms WHERE NOT EXISTS (SELECT * FROM room_events WHERE room_start BETWEEN '1294727400' AND '1294729200' OR room_finish BETWEEN '1294727400' AND '1294729200') table a contains multiple rooms, table b contains room events I am getting no results in case there is any event for any of the

How can I do an insert where not exists?

强颜欢笑 提交于 2019-11-27 15:51:07
问题 I'd like to combine an insert query with a "where not exists" so as not to violate PK constraints. However, syntax such as the following gives me an Incorrect syntax near the keyword 'WHERE' error - INSERT INTO myTable(columns...) VALUES(values...) WHERE NOT EXISTS (SELECT * FROM myTable WHERE pk_part1 = value1, AND pk_part2 = value2) How can I accomplish this? (In general, can you combine an insert with a where clause?) 回答1: INSERT INTO myTable(columns...) Select values... WHERE NOT EXISTS

MySQL Join Where Not Exists

纵饮孤独 提交于 2019-11-27 11:25:05
I have a MySQL query that joins two tables Voters Households they join on voters.household_id and household.id Now what i need to do is to modify it where the voter table is joined to a third table called elimination, along voter.id and elimination.voter_id, how ever the catch is that i want to exclude any records in the voter table that have a corresponding record in the elimination table. how do i craft a query to do this? this is my current query SELECT `voter`.`ID`, `voter`.`Last_Name`, `voter`.`First_Name`, `voter`.`Middle_Name`, `voter`.`Age`, `voter`.`Sex`, `voter`.`Party`, `voter`.

Mysql: Perform of NOT EXISTS. Is it possible to improve permofance?

空扰寡人 提交于 2019-11-27 08:16:15
问题 I have two tables posts and comments . Table comments have post_id attribute. I need to get all posts with type "open", for which there are no comments with type "good" and created date MAY 1. Is it optimal to use such SQL-query: SELECT posts.* FROM posts WHERE NOT EXISTS ( SELECT comments.id FROM comments WHERE comments.post_id = posts.id AND comments.comment_type = 'good' AND comments.created_at BETWEEN '2010-05-01 00:00:00' AND '2010-05-01 23:59:59') I'm not sure that NOT EXISTS is perfect

Mysql select where not in table

…衆ロ難τιáo~ 提交于 2019-11-27 03:12:12
I have 2 tables (A and B) with the same primary keys. I want to select all row that are in A and not in B. The following works: select * from A where not exists (select * from B where A.pk=B.pk); however it seems quite bad (~2 sec on only 100k rows in A and 3-10k less in B) Is there a better way to run this? Perhaps as a left join? select * from A left join B on A.x=B.y where B.y is null; On my data this seems to run slightly faster (~10%) but what about in general? I use queries in the format of your second example. A join is usually more scalable than a correlated subquery. Nick Berardi I

Add a column to a table, if it does not already exist

安稳与你 提交于 2019-11-26 22:39:13
问题 I want to write a query for MS SQL Server that adds a column into a table. But I don't want any error display, when I run/execute the following query. I am using this sort of query to add a table ... IF EXISTS ( SELECT * FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'[dbo].[Person]') AND TYPE IN (N'U') ) But I don't know how to write this query for a column. 回答1: You can use a similar construct by using the sys.columns table io sys.objects . IF NOT EXISTS ( SELECT * FROM sys.columns WHERE